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

2

7

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.

Huelva answered 12/8, 2010 at 11:7 Comment(1)
you mention 1.36 two times, but the linker output says 1.35?Chimb
H
1

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

Higher answered 15/1, 2018 at 9:58 Comment(1)
I am no longer at that company, and I think in the end they just moved over to the DLL version, but I think your answer is correct so I will mark it as suchHuelva
C
2

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...

Chimb answered 2/9, 2012 at 3:2 Comment(1)
Beginning with Boost 1.52 this is possible.Teutonic
H
1

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

Higher answered 15/1, 2018 at 9:58 Comment(1)
I am no longer at that company, and I think in the end they just moved over to the DLL version, but I think your answer is correct so I will mark it as suchHuelva

© 2022 - 2024 — McMap. All rights reserved.