LNK1104: cannot open file 'libboost_thread-vc100-mt-sgd-1_42.lib'

10,898 views
Skip to first unread message

Therefore

unread,
Aug 21, 2012, 5:40:07 PM8/21/12
to mongod...@googlegroups.com
Windows 7 64 SP1
MongoDB 2.0.6
Boost 1.42
MS VS 2010 Ultimate

I've added to VS project properties ws2_32.lib, include directories for mongo and boost, /MT and  _CRT_SECURE_NO_WARNINGS.

I'm trying to build the sample tutorial.cpp. I get this fatal error:

        LNK1104: cannot open file 'libboost_thread-vc100-mt-sgd-1_42.lib'

In "C:\boost\stage\lib" and "C:\boost\bin.v2\libs\thread\build\msvc-10.0\debug\link-static\threading-multi" I have the file:

         libboost_thread-vc100-mt-gd-1_42.lib
        
but not libboost_thread-vc100-mt-sgd-1_42.lib ("-sgd-" vs. "-gd-") anywhere.

Thoughts?

Mark

Tad Marshall

unread,
Aug 22, 2012, 5:19:22 AM8/22/12
to mongod...@googlegroups.com
This variant is for statically linking against the C runtime library.  You can either tell Visual Studio to use the debug DLL version of the library (which will use your -gd- version) or build the -sgd- version yourself.  If you build the complete set of Boost libraries it should include this one.  The code will be built to (for example) C:\boost_1_42_0\bin.v2\libs\thread\build\msvc-10.0\debug\link-static\runtime-link-static\threading-multi\libboost_thread-vc100-mt-sgd-1_42.lib and will be copied to C:\boost_1_42_0\stage\lib.  You can pass a set of options on the command line to Boost's bjam.exe to build just the specific variant that you need; see http://www.boost.org/doc/libs/1_42_0/more/getting_started/windows.html#library-naming for details.  Ordinarily, you could download pre-built libraries from http://www.boostpro.com/download/ , but for Boost version 1.42 they don't have a Visual Studio 2010 set, so for 1.42 and VC 10.0 you need to build your own.

Therefore

unread,
Aug 22, 2012, 4:55:55 PM8/22/12
to mongod...@googlegroups.com
Hi Tad,

Thank you for the help and your time (and patience). I had built the Boost 1.42 with bjam knowing that was a requirement for VS 2010 but didn't do it properly. I tried:

   bjam toolset=msvc-10.0 variant=release threading=multi link=static
   bjam toolset=msvc-10.0 variant=debug threading=multi link=static

hoping for the static build. So, taking your advice (via the boost link) I did the whole thing:

      bjam --build-type=complete msvc stage

and lo-and-behold, there was my -sgd- version. Added "C:\boost_1_42_0\stage\lib" to "VS->Configuration Properties->Linker->General->Additional Library Directories"

and that error went away. So much thanks.

Now I'll work on my "LNK2005: ___ already defined in ..." errors.But I'm sure I'll figure that out following the advice at http://www.mongodb.org/pages/viewpage.action?pageId=21266598 "Windows troubleshooting". I'll post a different thread on the chance I don't nail this down.

Thanks again for your time,

Mark


Therefore

unread,
Aug 25, 2012, 6:28:10 PM8/25/12
to mongod...@googlegroups.com

On Wednesday, August 22, 2012 2:19:22 AM UTC-7, Tad Marshall wrote:
This variant is for statically linking against the C runtime library.  You can either tell Visual Studio to use the debug DLL version of the library (which will use your -gd- version) or build the -sgd- version yourself.

Well, I'm right back at this problem again. I tried to:

1. downloaded boost_1_42_0.7z from boost.org, unpacked it into C:\boost_1_42_0\ and renamed to c:\boost\.

2. Then with MS VS x64 Command Prompt:

    cd c:\boost
    bjam msvc stage --build-type=complete address-model=64

3. scons --64

    scons --dd --64 mongoclient.lib

    scons --dd --64 core
   
4. I added to MS VS Properties: Configuration Properties->vc++ Directories->Include Directories

     c:\boost
    
5. I added to MS VS Properties: Configuration Properties->Linker->General->Additional Library Directories

      c:\boost\stage\lib

6. I set Properties: Configuration Properties-> C/C++->Code Generation select:

                     /MTd

The result is:

The result is 55 LINK2019 unresolved externals. E.g.,

1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>Start mongo.obj : error LNK2001: unresolved external symbol "protected: static struct mongo::AtomicUInt mongo::DBClientConnection::_numConnections" (?_numConnections@DBClientConnection@mongo@@1UAtomicUInt@2@A)
1>Start mongo.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall mongo::DBClientBase::insert(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class mongo::BSONObj,class std::allocator<class mongo::BSONObj> > const &,int)" (?insert@DBClientBase@mongo@@UAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@VBSONObj@mongo@@V?$allocator@VBSONObj@mongo@@@std@@@4@H@Z)
1>Start mongo.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall mongo::DBClientBase::insert(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class mongo::BSONObj,int)" (?insert@DBClientBase@mongo@@UAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VBSONObj@2@H@Z)

So, I decided to take another route to build boost:

1. Make sure I had 32 bit Python.

2. run buildboost64.bat from c:\mongodb\buildscripts (after mkdir c:\boost\bin and c:\boost\lib and copy bjam.exe into /bin)

3. scons --64

    scons --dd --64 mongoclient.lib

    scons --dd --64 core

4. Similar settings in MS VS.

And now I'm right back to:


LNK1104: cannot open file 'libboost_thread-vc100-mt-sgd-1_42.lib'

Plus a series of warnings:

c:\mongodb\db\../util/mmap.h(269): warning C4267: 'initializing' : conversion from 'size_t' to 'unsigned int', possible loss of data
1>c:\mongodb\db\../util/mmap.h(270): warning C4267: 'initializing' : conversion from 'size_t' to 'unsigned int', possible loss of data
1>c:\mongodb\util\net\../mongoutils/str.h(73): warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
1>c:\mongodb\util\net\../mongoutils/str.h(74): warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
1>c:\mongodb\client\../util/net/message.h(282): warning C4267: 'argument' : conversion from 'size_t' to 'unsigned long', possible loss of data
1>c:\mongodb\client\dbclientcursor.h(55): warning C4267: 'return' : conversion from 'size_t' to 'int', possible loss of data

So, can you tell me how to " tell Visual Studio to use the debug DLL version of the library (which will use your -gd- version) " and I can just forget the -gds-? What would be the difference as far as the MongoDB C++ driver is concerned?

Thanks,

Mark






Tad Marshall

unread,
Aug 25, 2012, 8:27:43 PM8/25/12
to mongod...@googlegroups.com
To use the debug DLL version of the library, change your step 6 above to select "Multi-threaded Debug DLL (/MDd)" instead of "Multi-threaded Debug (/MTd)".  This should make the -gd- version of the the Boost libraries be what the build will be looking for.  It will make your program use (and therefore require) the debug C runtime DLLs msvcr100d.dll and msvcp100d.dll .  The Microsoft license does not allow these files to be redistributed but you'll find copies in the C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\redist\Debug_NonRedist\x64\Microsoft.VC100.DebugCRT directory (for x64) as well as in C:\Windows\system32.  It will make your compiled executable smaller (because it is now using the external DLL instead of including the code itself) but it shouldn't change the behavior of anything.  When (if) you build a release version of your program, you will want to choose "Multi-threaded DLL (/MD)" instead of "Multi-threaded (/MT)" for the same reasons, but the Microsoft license allows you to redistribute the release versions of the Microsoft libraries.

Thanks for pointing out buildscripts\buildboost64.bat ... I had never looked at this file, and it was never updated for when we added Boost to our source tree; it expects you to have downloaded Boost yourself.  It looks like it includes the "runtime-link=static link=static" options for the release build but not for the debug build.  Probably adding them to the debug line (the line that has "variant=debug") would get you the version of the library that your build wanted.

The multiple C4267 warnings are harmless, and we suppress them in the mongod.exe (etc.) builds by adding 4267 (and a few others) to the "Disable specific warnings" setting in project properties for Visual Studio and with "/wd4267" in the scons build.

Therefore

unread,
Aug 25, 2012, 8:53:26 PM8/25/12
to mongod...@googlegroups.com
Good, progress! Thanks so much! Now I am where I was with plan A's boost building. First, here are my exact mods to configuration:

Using Debug/x64 via configuration error.

Properties: Configuration Properties->vc++ Directories->Include Directories add:

     c:\mongodb
     c:\boost

Properties: Configuration Properties->Linker->General->Additional Library Directories add:

      c:\boost\lib
      c:\mango (the location of mongoclient.lib)


Properties: Configuration Properties-> C/C++->Code Generation select:

                     /MDd

Properties: Configuration Properties --> C/C++ -> Preprocessor->Precprocessor Definitions add:

                    _CRT_SECURE_NO_WARNINGS

Properties: Configuration Properties->Linker->Input->Additional Dependencies add:

                 ws2_32.lib

Here is my simple source:

#include "StdAfx.h"
#include <iostream>
#include "client/dbclient.h"

using namespace mongo;

void run() {
  DBClientConnection c;
  c.connect("localhost");
}

int main() {
  try {
    run();
    cout << "connected ok" << endl;
  } catch( DBException &e ) {
    cout << "caught " << e.what() << endl;
  }
  return 0;
}

I get many of these:

1>connectMongo.obj : error LNK2001: unresolved external symbol "protected: static struct mongo::AtomicUInt mongo::DBClientConnection::_numConnections" (?_numConnections@DBClientConnection@mongo@@1UAtomicUInt@2@A)
1>connectMongo.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl mongo::DBClientBase::insert(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class mongo::BSONObj,class std::allocator<class mongo::BSONObj> > const &,int)" (?insert@DBClientBase@mongo@@UEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV?$vector@VBSONObj@mongo@@V?$allocator@VBSONObj@mongo@@@std@@@4@H@Z)
1>connectMongo.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl mongo::DBClientBase::insert(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class mongo::BSONObj,int)" (?insert@DBClientBase@mongo@@UEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VBSONObj@2@H@Z)
1>connectMongo.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl mongo::DBClientBase::remove(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class mongo::Query,bool)" (?remove@DBClientBase@mongo@@UEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VQuery@2@_N@Z)
1>connectMongo.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl mongo::DBClientBase::update(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class mongo::Query,class mongo::BSONObj,bool,bool)" (?update@DBClientBase@mongo@@UEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VQuery@2@VBSONObj@2@_N3@Z)
1>connectMongo.obj : error LNK2001: unresolved external symbol "public: virtual class mongo::BSONObj __cdecl mongo::DBClientInterface::findOne(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class mongo::Query const &,class mongo::BSONObj const *,int)" (?findOne@DBClientInterface@mongo@@UEAA?AVBSONObj@2@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVQuery@2@PEBV32@H@Z)
1>connectMongo.obj : error LNK2001: unresolved external symbol "public: virtual class std::auto_ptr<class mongo::DBClientCursor> __cdecl mongo::DBClientBase::getMore(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,__int64,int,int)" (?getMore@DBClientBase@mongo@@UEAA?AV?$auto_ptr@VDBClientCursor@mongo@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@_JHH@Z)
...

Is it not finding my mongoclient.lib?

Where in the properties do I tell it to ignore specific errors?

Thanks Tad. I have never lost faith that I can do this. :)

Mark

Therefore

unread,
Aug 25, 2012, 9:27:53 PM8/25/12
to mongod...@googlegroups.com
Ack, of course I know how to suppress particular warnings. It's been a long day.

Therefore

unread,
Aug 25, 2012, 9:41:35 PM8/25/12
to mongod...@googlegroups.com
Success. I explicitly added "C:\mongodb\mongoclient.lib" to:

Properties: Configuration Properties->Linker->Input->Additional Dependencies.

And now all compiles fine. Should I have known to do this? Shouldn't it have found it via "C:\mongodb" in the Additional Library Directories?

I'm going to write up a how-to on this and post it once I got this all figured out.

Thanks!

Tad Marshall

unread,
Aug 26, 2012, 8:00:25 AM8/26/12
to mongod...@googlegroups.com
Congratulations on getting it working!  I know you've been hitting a lot of problems.  A writeup of what you had to do to get it working would be a great public service, thanks in advance!

The Microsoft linker needs to be told by one mechanism or another what libraries you want to link with, because the same symbol might be available in more than one library and you need to have control over what gets included in your executable.  Boost uses a #pragma in its source code to tell the linker to include a specific library, which is why you get different requirements when you build with different options.  Because the MongoDB C++ driver is really a subset of the source code from MongoDB itself, it would be hard for us to do this in a way that didn't cause more problems than it solved.  Adding mongoclient.lib to the list of linker dependencies for your program, as you did, is the right way to get the code included in your build.

Thanks for persisting through your build problems, good luck!
Reply all
Reply to author
Forward
0 new messages