1. 程式人生 > >QT編譯時出現 : warning LNK4098: 預設庫“msvcrtd.lib”與其他庫的使用衝突;請使用 /NODEFAULTLIB:library

QT編譯時出現 : warning LNK4098: 預設庫“msvcrtd.lib”與其他庫的使用衝突;請使用 /NODEFAULTLIB:library

1.問題復現:

     本人公司使用的是qt5.3 + vs2015開發,但是家裡電腦使用的是qt5.2 + vs2010進行開發。每次在公司寫好部分功能,想拿到家繼續開發時,專案編譯出現下列問題:     

1)msvcrtd.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" ([email protected]@[email protected]@@Z) 已經在 LIBCMTD.lib(typinfo.obj) 中定義

2)msvcrtd.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (
[email protected]
@[email protected]@@Z) 已經在 LIBCMTD.lib(typinfo.obj) 中定義 3)LIBCMTD.lib(crt0init.obj) : warning LNK4098: 預設庫“msvcrtd.lib”與其他庫的使用衝突;請使用 /NODEFAULTLIB:library debug\ElectromechanicalControl.exe : fatal error LNK1169: 找到一個或多個多重定義的符號

2.解決方法:

到工程管理目錄下(.pro)檔案中加入下列程式碼:

QMAKE_CXXFLAGS_RELEASE = -O2 -MD -GL
QMAKE_CXXFLAGS_DEBUG = -Zi -MDd

重新編譯後,問題解決。

3.問題深究:

MSDN上的解釋為:

You are trying to link with incompatible libraries.

Important   The run-time libraries now contain directives to prevent mixing different types. You’ll receive this warning if you try to use different types or debug and non-debug versions of the run-time library in the same program. For example, if you compiled one file to use one kind of run-time library and another file to use another kind (for example, single-threaded versus multithreaded) and tried to link them, you’ll get this warning. You should compile all source files to use the same run-time library.

一句話,lib之間有衝突。需要刪除匯入的一些libs。

報錯中,顯示是LIBCMTD.lib與msvcrtd.lib衝突,所以我們選擇使用DLL的多執行緒,所以,在引數中設定為

-MD/-MDd