(1)錯誤案例:在寫日誌程序中出現,工程是MFC程序(注:win32控制檯應用程序,不會出現這種錯誤,固然是不支持MFC庫的那種)多線程
(2)錯誤緣由:以下能看出一點眉目,重定義了.在使用***.obj時,已經在***.lib庫中定義了.this
摘抄:spa
上網搜了下,是CRT庫與MFC庫的衝突,解決方法是:讓程序先連接Nafxcwd.lib,而後再連接Libcmtd.lib線程
you've got to change the order inwhich the libraries are linked. This is a bit tricky, since the library are linked automatically, without you explicitly specifying them.
So, first step, tell the linker to ignore the implicit libraries: Project/Setting/Linker, Input Tab, and put "Nafxcwd.lib Libcmtd.lib" in the "Libraries to Ignore" box.
Next, on the same page, in the Object/library Modules box, put the same to libraries. (in you still get the same error, try reversing them on this line)日誌
能夠從錯誤信息裏看到,操做符new,delete,delete[]已經在LIBCMTD.lib中定義了,這跟C編譯時使用的默認庫與MFC運行時的默認編譯庫編譯時連接順序有關,咱們能夠手動的改變兩個庫的編譯順序就能解決這個定義衝突問題。ci
(3)錯誤現場:get
1>正在連接...
1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" () 已經在 LIBCMTD.lib(new.obj) 中定義
1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" () 已經在 LIBCMTD.lib(dbgdel.obj) 中定義
1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" () 已經在 libcpmtd.lib(newaop.obj) 中定義
1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" () 已經在 LIBCMTD.lib(delete2.obj) 中定義
1>C:\Documents and Settings\Administrator\桌面\多線程寫日誌怎樣寫\寫日誌1\Debug\寫日誌1.exe : fatal error LNK1169: 找到一個或多個多重定義的符號it
(4)錯誤解決辦法:編譯
中文class
項目--屬性 ---鏈接器---輸入
附加依賴項 空格Nafxcwd.lib Libcmtd.lib
忽略指定庫 空格Nafxcwd.lib Libcmtd.lib
清除項目。從新編譯。搞定