开发者

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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜