最近为了解决跨lib之间vector产生的问题,将link的Code Generation的Use run-time library 修改为MultiThreaded Dll,结果导致了系列错误。
LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrt.lib(MSVCRT.dll)
LIBCMT.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrt.lib(MSVCRT.dll)
LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrt.lib(cinitexe.obj)
LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrt.lib(cinitexe.obj)
LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrt.lib(cinitexe.obj)
LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrt.lib(cinitexe.obj)
LIBCMT.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrt.lib(MSVCRT.dll)
LINK : warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of other libs; use /NODEFAULTLIB:library
LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Release/数据库端.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
后来经上网查询,得到了解决方法。
涉及到多线程编程。若使用到动态库时,没有问题。用静态库,由于lib冲突,会出现编译错误。
1.使用静态库链接,或不用
2.设置-》c/c++->分类(code generation)->use run time library(选择MD,若是debug选择DMD)
3.在设置-》c/c++->分类(常规)-》预处理定义里加入 ,_AFXDLL
文章来源:http://hi.baidu.com/tracy_2008/item/907f3a173e4b91fd756a849a