Subscribe to RSS

Linking Boost and MFC

Back to MainPage. Back to ProgrammingStuff.

Linking against Boost can sometimes be tricky, as a minor misconfiguration in your project / makefiles can cause the auto-link mechanism to operate differently than you expect. Here's one example of a failure during link:

libboost_thread-vc80-mt-1_40.lib(tss_pe.obj) : error LNK2005:
__pRawDllMain already defined in mfcs80.lib(rawdllmainproxy.obj) Creating library c:\Work\MyLib\Release\MyLib.lib and object
c:\Work\MyLib\Release\MyLib.exp
.\Release\MyLib.dll : fatal error LNK1169:
one or more multiply defined symbols found

In this example, MFC already defines this symbol to do it's own setup during dll load or attach. The Boost::Thread library tries to do the same, with the laudable intent to initialize or teardown everything correctly. Only one actor can use this mechanism, so we'll have to modify one.

Option 1: Cause the boost thread library to be used dynamically. The preprocessor definition BOOST_ALL_DYN_LINK can be used to force all boost libraries to be used dynamically. Note that the define BOOST_LIB_DIAGNOSTIC can be used to get more info for debugging the build process.

Option 1 (continued): If you want to explicitly select libraries to link against dynamically, use preprocessor def's such as: BOOST_DATE_TIME_DYN_LINK, or BOOST_REGEX_DYN_LINK. Nota bene: For the Boost::Thread library, the define is incorrectly BOOST_THREAD_DYN_DLL instead of BOOST_THREAD_DYN_LINK. This bug was fixed around May 2010.

Option 2: Remove MFC. Do you really need MFC?

Back to MainPage. Back to ProgrammingStuff.

Edited on Mon, Feb 28, 2011 at 3:47 a.m.