連接報錯:
錯誤
33 error LNK2005: _DllMain@12 已經在 MSVCRTD.lib(dllmain.obj) 中定義 E:\客戶問題\w_王鵬\EventLibTest_TibrvAlternative_MultiEnv-4-0.3將 DTSSysEvent.xml作爲單獨參數傳給每一個環境\EventLibTest_TibrvAlternative_MultiEnv\Win32 \APPFL\EventLibMultiEnvDLL\mfcs100d.lib(dllmodul.obj) EventLibMultiEnvDLL (Visual Studio 2010)
解決方法:
項目-》屬性-》配置屬性-》C/C++/預處理器,去掉預處理器定義中的_USRDLL 便可
另外:
常見預處理器設置的意義:
http://blog.csdn.net/honker110/article/details/6120810
常見的編譯參數VC創建項目時總會定義"Win32"。控制檯程序會定義"_CONSOLE",不然會定義"_WINDOWS"。Debug版定義"_DEBUG",Release版定義"NDEBUG"
與MFC DLL有關的編譯常數包括:
_WINDLL 表示要作一個用到MFC的DLL
_USRDLL 表示作一個用戶DLL(相對MFC擴展DLL而言)
_AFXDLL 表示使用MFC動態連接庫的 regular DLL
_AFXEXT 表示要作一個MFC擴展DLL
因此:
Regular, statically linked to MFC _WINDLL,_USRDLL
Regular, using the shared MFC DLL _WINDLL,_USRDLL,_AFXDLL
Extension DLL _WINDLL,_AFXDLL,_AFXEXT
Building Your DLL
When compiling regular DLLs that statically link to MFC, the symbols "_USRDLL" and "_WINDLL" must be defined. Your DLL code must also be compiled with the following compiler switches:
•/D_WINDLL signifies the compilation is for a DLL
•/D_USRDLL specifies you are building a regular DLL
When compiling regularDLLs that statically link to MFC, the symbols "_USR DLL" and"_WINDLL" must be defined. Your DLL code must also be compile dwith the following compiler switches:
When compiling regular DLLs that dynamicallylink to MFC, you must define t he above symbols and use the above compilerswitches. Additionally, the sy mbol "_AFXDLL" must be definedand your DLL code must be compiled with:
•/D_AFXDLL specifies that you are building a regular DLL that dynamicall y links to MFC
The interfaces (APIs) between the application and the DLL must beexplicitlyexported. It is recommended that you define your interfaces to be lowbandw idth, sticking to C interfaces where possible. More direct C interfaces areeasi er to maintain than more complex C++ classes.
Place your APIs in aseparate header that can be included by both C and C++files (that way you won'tlimit your DLL customers to C++ programmers). Se e the header ScreenCap.h in theMFC Advanced Concepts sample DLLScreen Cap for an example. To export yourfunctions, enter them in theEXPORTSs ection of your moduledefinition file (.DEF) or include__declspec(dllexpor t)on yourfunction definitions. Use__declspec(dllimport)to import thesefunctions into the client executable.
You must add theAFX_MANAGE_STATEmacro at the beginning of all the e xportedfunctions in regular DLLs that dynamically link to MFC to set the curr ent modulestate to the one for the DLL. This is done by adding the followingline of codeto the beginning of functions exported from the DLL:
AFX_MANAGE_STATE(AfxGetStaticModuleState( ))
WinMain->DllMain
The MFC library defines the standard Win32DllMain entry point that initializ es yourCWinAppderived object as in a normal MFC application. Placeall DLL-specific initialization in theInitInstancememberfunction as in a normal MFC application.
經驗證可行
轉自 http://blog.csdn.net/tian_jinping/article/details/14168919
或使用以下方法,是的mfc庫先於msvcrtd.lib連接
_DllMain@12 已經在 MSVCRTD.lib(dllmain.obj) 中定義 VC2005解決辦法: 1)Debug版本: 項目-屬性-連接器-輸入:忽略特定庫中輸入mfc80d.lib;mfcs80d.lib 項目-屬性-連接器-附加依賴項:mfc80d.lib;mfcs80d.lib 就能夠保證mfc80d和mfcs80d先於MSVCRTD.lib連接,OK,成功 2)Release版本 與Debug版本不一樣在於mfc80.lib;mfcs80.lib