How to link with Boost Library in Windows

 

There’s a well prepared documentation for Boost library which is available at Boost Website. What I’m trying to say is some of the important points on using the library, and this can be considered as an excerpt of the Boost documentation.

  • First of you compiler must support #pragma comment(lib, name)feature.
  • If you are choosing Dynamic runtime, there will be an option to link statically or dynamically with the boost library. Boost will be linking statically by default.
  • You can alter the default static linking to a specific library by defining BOOST_LIBRARY_NAME_DYN_LINK. Library name should be replaced properly with the library name. We can also force all library to link dynamically by defining BOOST_ALL_DYN_LINK preprocessor.
  • This feature can be disabled for Boost library whatever by defining BOOST_WHATEVER_NO_LIB, or for all of Boost by defining BOOST_ALL_NO_LIB. (taken from Boost documentation)
  • By defining BOOST_LIB_DIAGNOSTIC will cause  the auto-linking code to emit a #pragma message each time a library is selected for linking. So we can verify which all libraries are being linked against.
  • For using the auto linking feature of Boost.Threads, we have to define BOOST_THREAD_USE_DLL or and BOOST_THREAD_USE_LIB). If none of the above defined, the default will be chosen
  • There are some specific libraries which does not support automatic linking.

See the complete documentation on auto linking under Windows

 

Sample defines

// Link all libraries dynamically
#define BOOST_ALL_DYN_LINK
// For linking with boost.thread not supported by ‘BOOST_ALL_DYN_LINK’
#define BOOST_THREAD_USE_DLL
// Verbose
#define BOOST_LIB_DIAGNOSTIC

 
  • http://ngpanwei.com/?p=587 Compiling Boost Threads on Visual C++ 2008 and MinGW « Ng Pan Wei

    [...] Debug (/MTd), but I am not sure what are the effects otherwise. There is some discussion in codereflect.com. C/C++, Programming Languages    Discrete Event Simulation (DEVS) and the [...]