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 &)" (??0type_info@@AAE@ABV0@@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 &)" (??4type_info@@AAEAAV0@ABV0@@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