Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade of BOOST 1.35 to 1.43 causes linker error with __pRawDllMain (mfc related)

At work we have an MFC Extension DLL that built fine with 1.35 but when built with 1.43 causes the following error:

error LNK2005: __pRawDllMain already defined in ApObs.obj

If I activate BOOST_LIB_DIAGNOSTIC the old build lists:

linking to lib file: libboost_thread-vc71-mt-gd-1_35.lib

and

linking to lib file: libboost_thread-vc71-mt-gd-1_43.lib

So no change there with which library is linked

The full error message is:

libboost_thread-vc71-mt-gd-1_43.lib(tss_pe.obj) : error LNK2005: __pRawDllMain already defined in ApObs.obj

I have done a diff on tss_pe.cpp in both library versions and they are identical, so I'm not sure what the problem is.

You can get the message to disappear by defining BOOST_THREAD_USE_DLL but then we would need to ship BOOST_THREAD-VC71-MT-GD-1_43.DLL so I don't think this is the best solution.

like image 224
Peter Nimmo Avatar asked Aug 12 '10 11:08

Peter Nimmo


2 Answers

There is known incompatibility between MFC and statically linked boost Thread, both trying to hook into DllMain to initialize stuff. This has been introduced in boost 1.37.

From the author of boost::thread:

If you can ensure that on_process_exit from boost/thread/detail/tss_hooks.hpp is called when the DLL is unloaded then you can patch libs/thread/src/win32/tss_pe.cpp to remove the use of _pRawDllMain.

(He recommends to use the DLL version, though.)

There seem to have been efforts to make this patching unnecessary, but apparently to no avail so far...

like image 162
Daniel S Avatar answered Sep 25 '22 02:09

Daniel S


This happens because of the linking order.
You can change the linking error by manually adding the libs in the Additional Dependencies.
In my case putting libboost_thread-vc71-mt-gd-1_43.lib BEFORE the other conflicting lib solved the problem:

Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies

libboost_thread-vc80-mt-1_40.lib;mfcs80u.lib;%(AdditionalDependencies)

Note that in my case it was conflicting with mfcs80u.lib

like image 28
Yochai Timmer Avatar answered Sep 23 '22 02:09

Yochai Timmer