一.首先是”Invalid Address specified to RtlValidateHeap
“
找到了這篇文章:http://hi.baidu.com/umu618/blog/item/d4e8242e424e3e564fc226d3.html
“一個可能的原因:在不同模組(工程)之間傳遞 C++ 類,而這兩個模組用了不同的執行階段程式庫(Runtime Library)設定。例如:EXE 模組調用 DLL 模組裡傳遞 C++ 類的函數,但 DLL 模組使用靜態連結(Release 是 Multi-threaded (/MT)
、Debug 是 Multi-threaded Debug (/MTd)
)方式編譯,而 EXE 模組使用動態連結(Release 是 Multi-threaded DLL (/MD)
、Debug 是 Multi-threaded Debug DLL (/MDd)
)方式編譯。
可以對比這兩個模組的工程屬性 - C/C++ - Code Generation - Runtime Library
,看看設定是否一樣,如果不一樣要改成一樣的。“
二.把我的exe工程屬性改成和dll一樣的Multi-threaded Debug DLL (/MDd)後,
出現nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
找到這篇文章:http://blog.csdn.net/pbdwadr/archive/2007/09/07/1775675.aspx,如下:
”
1. 【錯誤提示】:
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
【說 明】: Windows項目要使用Windows子系統, 而不是Console
【解決方案】:[Project] --> [Settings] --> 選擇"Link"屬性頁面,
在Project Options中將/subsystem:console改成/subsystem:windows
2. 【錯誤提示】:LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol
_WinMain@16
【說 明】:控制台項目要使用Console子系統, 而不是Windows
【解決方案】:[Project] --> [Settings] --> 選擇"Link"屬性頁面,
在Project Options中將/subsystem:windows改成/subsystem:console
3. 【錯誤提示】:msvcrtd.lib(crtexew.obj) : error LNK2001: unresolved external symbol
_WinMain@16
【說 明】:通常, MFC項目的程式入口函數是WinMain, 如果編譯項目的Unicode版本, 程式入 口必須改為wWinMainCRTStartup, 所以需要重新設定程式入口
【解決方案】:[Project] --> [Settings] --> 選擇"C/C++"屬性頁面,
在Category中選擇Output,
再在Entry-point symbol中填入wWinMainCRTStartup, 即可 4. 【錯誤提示】:
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
【說 明】:這是因為MFC要使用多線程時庫 【解決方案】:[Project] --> [Settings] --> 選擇"C/C++"屬性頁面,
在Category中選擇Code Generation,
再在Use run-time library中選擇Debug Multithreaded或者multithreaded
其中,
Single-Threaded 單線程靜態連結庫(release版本)
Multithreaded 多線程靜態連結庫(release版本)
multithreaded DLL 多線程動態連結程式庫(release版本)
Debug Single-Threaded 單線程靜態連結庫(debug版本)
Debug Multithreaded 多線程靜態連結庫(debug版本)
Debug Multithreaded DLL 多線程動態連結程式庫(debug版本)
單線程: 不需要多線程調用時, 多用在DOS環境下
多線程: 可以並發運行
靜態庫: 直接將庫與程式Link, 可以脫離MFC庫運行
動態庫: 需要相應的DLL動態庫, 程式才能運行
release版本: 正式發布時使用
debug版本: 調試階段使用5. 【錯誤提示】:
Compiling... ,Error spawning cl.exe 【說 明】:這個問題很多情況下是由於路徑設定的問題引起的,“CL.exe”是VC使用真正 的編譯器(編譯器),其路徑在“VC根目錄/VC98/Bin”下面,你可以到相 應的路徑下找到這個應用程式。
【解決方案】:“TOOLS(工具)”—>“Option(選擇)”—>“Directories(目錄)” 重新設定“Excutable Fils、Include Files、Library Files、Source Files”的路徑。6. 【錯誤提示】:
nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
【說 明】:
【解決方案】:在Preprocessor中定義_AFXDLL7. 【錯誤提示】:fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds
【說 明】: 【解決方案】:/C++->Code Generation->Multithread DLL (即實現/MD選項)
“
按照方法6解決
三.一個相關的問題
nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in utility.obj幾種解決方案:(以前的筆記,忘記其中的一些原帖了)
1.
你只需要在工程設定裡面,把
WIN32,NDEBUG,_WINDOWS,_MBCS,_USRDLL,MSGBOX_EXPORTS,_WINDLL,_AFXDLL
中的_USRDLL,刪除,就可以正確編譯了
另一種描述
nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined
google半天沒搞定
只好自己搞,最後將工程裡面的_USRDLL宏定義去除,瞎貓碰到死耗子了,好了。
在afx.h中發現一段代碼
#ifdef _USRDLL
#pragma comment(linker, "/include:__afxForceUSRDLL")
#endif
就我現在的水平,沒看懂,留著以後慢慢看吧,呵呵!
2.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. 4.官方解決方案 :http://support.microsoft.com/kb/148652/zh-cn
在 Visual C++ 中以錯誤的順序連結 CRT 庫和 MFC 庫時出現 LNK2005 錯誤