libcmtd.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll) 编译错误解决方法

[问题描述]

今天在VC6下编译G279软件时,已编译通过,链接时报一下错误:

Linking...
libcmtd.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
libcmtd.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCRTD.dll)
libcmtd.lib(strcat.obj) : error LNK2005: _strcpy already defined in msvcrtd.lib(MSVCRTD.dll)
libcmtd.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrtd.lib(MSVCRTD.dll)
libcmtd.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
libcmtd.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
libcmtd.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
libcmtd.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
libcmtd.lib(atox.obj) : error LNK2005: _atoi already defined in msvcrtd.lib(MSVCRTD.dll)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: _strncpy already defined in libcmtd.lib(strncpy.obj)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __snprintf already defined in libcmtd.lib(snprintf.obj)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __setmbcp already defined in libcmtd.lib(mbctype.obj)
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
msvcrtd.lib(cinitexe.obj) : warning LNK4098: defaultlib "libcmtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/LanVoice.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

LanVoice.exe - 14 error(s), 2 warning(s)
这样的问题在以前也遇到过,只是没有在意,细细想一想,问题的原因上面已经指出,就是红色那一句,默认的"libcmtd.lib"和其他的一些libs有冲突,可以用/NODEFAULTLIB:library设置屏蔽掉默认的libcmtd.lib

在Project中打开Project Setting设置对话框,选择Link选中Category旁边下拉框的Input项。

在Ignore Libraries下面输入libcmtd.lib,将此屏蔽。

重新编译,链接,结果却大失所忘, 刚才的错误解决了,但新的错误却又出现了:

Linking...
LINK : warning LNK4049: locally defined symbol "_atoi" imported
LINK : warning LNK4049: locally defined symbol "_strncpy" imported
LINK : warning LNK4049: locally defined symbol "__snprintf" imported
LINK : warning LNK4049: locally defined symbol "__setmbcp" imported
jrtplib.lib(rtprandom.obj) : error LNK2001: unresolved external symbol __imp__srand
jrtplib.lib(rtprandom.obj) : error LNK2001: unresolved external symbol __imp__clock
jrtplib.lib(rtprandom.obj) : error LNK2001: unresolved external symbol __imp__time
jrtplib.lib(rtprandom.obj) : error LNK2001: unresolved external symbol __imp___getpid
jrtplib.lib(rtprandom.obj) : error LNK2001: unresolved external symbol __imp__rand
jthread.lib(jthread.obj) : error LNK2001: unresolved external symbol __imp___beginthreadex
Debug/LanVoice.exe : fatal error LNK1120: 6 unresolved externals
Error executing link.exe.

LanVoice.exe - 7 error(s), 4 warning(s)
不要泄气,既然冲突是双方产生的,那一定就是屏蔽的库不对了,应该屏蔽这个库libcmtd.lib

果然重新编译一切OK。

回过头来,原来我的程序是USE mfc  in a share dll, libcmtd.lib是静态 C runtime库,所以应该屏蔽掉libcmtd.lib,以免造成冲突。

你可能感兴趣的:(libcmtd.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll) 编译错误解决方法)