在WIN32 DLL中使用MFC庫遇到的問題
今天寫了一個DLL,DLL中用到的一個類里用到的MSXML的COM組件,所以在DLL中要包含afx.h頭文件,也就不可避免的要用到MFC的類庫了,但在編譯時出現了錯誤:mfcs42d.lib(dllmodul.obj) : error LNK2005:_DllMain@12 already defined in NetDriverConfig.obj,
在http://topic.csdn.net/t/20010911/10/281452.html 處的貼子里找到了以下回答,試了一個原來是文件里定義的對象與mfcs42d.lib有沖突,加了命名空間后問題解決。還不知道DLL能不能使用,明天試一下再說了!
Linker Tools Error LNK2005
symbol already defined in object
The given symbol, displayed in its decorated form, was multiply defined.
Tips
One of the following may be a cause:
The most common cause of this error is accidentally linking with both the single-threaded and multithreaded libraries. Ensure that the application project file includes only the appropriate libraries and that any third-party libraries have appropriately created single-threaded or multithreaded versions.
The given symbol was a packaged function (created by compiling with /Gy) and was included in more than one file but was changed between compilations. Recompile all files that include the symbol.
The given symbol was defined differently in two member objects in different libraries, and both member objects were used.
An absolute was defined twice, with a different value in each definition.
Linker Tools Error LNK1169
one or more multiply defined symbols found
The build failed due to multiple definitions of one or more symbols. This error is preceded by error LNK2005.
The /FORCE or /FORCE:MULTIPLE option overrides this error.
-------------------------------------------------------------------------------------------------------------------------------------------------
今天又看了下發,發現在WIN32 DLL中使用MFC類庫是會存在問題,原因是在MFC/src/DLLModul.cpp 文件中已經聲明了DLLMain()函數,所以就不能在項目文件中再聲明 DllMain(),否則就會出現如上所示的鏈接錯誤。所以在WIN32 DLL中使用MFC類庫的話可以不聲明DLLMain()函數,如果有操作要放在DLL加載時初始化的話就從CWinApp派生一個類,在項目文件里聲明這個對象,在這個CWinApp類的InitInstance()成員函數中做初始化工作
RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成