Boost :: thread build error (cannot bind lib && unresolved external)

I am trying to execute a simple Boost :: Thread tutorial (version 1.4-3) in VS 2008:

#include <boost/thread/thread.hpp> void Func() { // Do something } void main() { boost::thread _thrd(&Func); _thrd.join(); .... } 

At compile time, it produces this error:

 Error 1 fatal error LNK1104: cannot open file 'libboost_thread-vc90-mt-gd-1_43.lib' CConsole 

which I have to solve by adding #define BOOST_ALL_NO_LIB . However, this gives me another error:

 Error 3 fatal error LNK1120: 2 unresolved externals C:\xx\Documents\Visual Studio 2008\Projects\CConsole\Debug\CConsole.exe Error 1 error LNK2019: unresolved external symbol "public: __thiscall boost::thread::~thread(void)" (??1thread@boost@@QAE@XZ) referenced in function _wmain CConsole.obj Error 2 error LNK2019: unresolved external symbol "private: void __thiscall boost::thread::start_thread(void)" (?start_thread@thread@boost@@AAEXXZ) referenced in function "public: __thiscall boost::thread::thread<void (__cdecl*)(void)>(void (__cdecl*)(void),struct boost::thread::dummy *)" (??$?0P6AXXZ@thread@boost@@QAE@P6AXXZPAUdummy@01@@Z) CConsole.obj 

Does anyone know how to solve a problem?

Thanks.

+7
c ++ multithreading boost visual-studio-2008-sp1
source share
2 answers

I think a deeper answer than “Read the F * cking manual” might be helpful!

Such a link error is the key you are trying to link to an incompatible Boost library.

I got this when I mistakenly built a 32-bit Boost thread library, when it seemed to me that I was building a 64-bit library. It took a while to realize that when you say --address-model=64 as the bjam command-line option, you made a subtle mistake. The address-model parameter must NOT have the -- prefix. Unfortunately, bjam does not tell you when it sees the wrong syntax.

You can use the dumpbin program to check the characters provided by your library, compared to characters that, according to the linker, are not allowed. I found that the library symbols were decorated with __thiscall , not __cdecl . This is a flashy good sign of architecture mismatch. The Microsoft compiler uses the __thiscall function call protocol for 32-bit assemblies, but it uses __cdecl for 64-bit assemblies. Yes, Microsoft documentation is a bit weak here!

The best way to check .lib or .dll to see how it was created is to use dumpbin. Here is an example:

 dumpbin /headers libboost_thread-vc100-mt-gd-1_45.lib | findstr machine 

You will need to adjust the name of the library to match what you link, of course. This will definitely show you whether .lib or .dll is for x86 (this is the 32-bit version) or x64 (64-bit version).

+21
source share

You need to create the Boost Thread library and tell Visual Studio where the library is. All of this is documented in the Getting Started documentation (i.e., getting started on Windows ). In particular, read section 5 , and then section 6 .

PS. You must make sure that your build configuration matches what you installed VS. The Getting Started section describes the various build options.

0
source share

All Articles