thread——MFC下Boost的线程编译错误问题

来源:互联网 发布:方维p2p 3.5 源码下载 编辑:程序博客网 时间:2024/06/04 00:23

在MFC中使用boost的多线程库,可能会抛出链接错误:

__pRawDllMain already defined in ....

这是由于thread的源码中叶有一个入口函数

extern BOOL (WINAPI * const _pRawDllMain)(HANDLE, DWORD, LPVOID)=&dll_callback;

解决方法是将

boost/libs/thread/src/win32/tss_pe.cpp

中的这句话注释然后重新编译即可解决。

 

网上看到另一种方法,经测试失败,如果测试成功请告之

 

链接:http://www.juicydata.com/LinkingMfcAndBoostThread

原文如下:

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?

 

当然,最好是这里的option2 开发前先思考一下,真的必须用MFC吗?

原创粉丝点击