Question

I am using boost's threading library and have run into linking issues in Visual Studio.

Right now, I'm compiling my VS project with /MT. The library I'm linking against is called libboost_thread-vc100-mt-1_48.lib, which seems to indicate that it, too has been compiled using /MT.

However, if I turn off all /MD related libraries in my linker settings (properties -> Linker -> Input -> Ignore Specific Default Libraries)...

msvcrt.lib 
msvcrtd.lib 
msvcprt.lib 
msvcprtd.lib

Then I get linker errors!

libboost_thread-vc100-mt-1_48.lib(thread.obj) : error LNK2001: unresolved external symbol __imp___gmtime64
libboost_thread-vc100-mt-1_48.lib(thread.obj) : error LNK2001: unresolved external symbol __imp___beginthreadex

How could this be possible just by turning off /MD related libraries? boost::thread should only be linking against libs in /MT (Which should be LIBCMT.LIB, LIBCPMT.LIB). Did I compile boost incorrectly?

Was it helpful?

Solution

BAM! Linker defeated!

It looks like my hunch was right. I didn't compile boost correctly. To emulate /MT with a boost build, you need to link against static runtime libraries (linking to dynamic runtime libraries seems to be the default).

The command to do this (for Release build of boost::thread) was:

.\b2 --with-thread variant=release link=static threading=multi runtime-link=static

Hope this helps someone out there using boost with /MT turned on in their project!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top