error LNK2005的解决

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

Linking...
libc.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
libc.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCRTD.dll)
libc.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
libc.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
libc.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
libc.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __setmbcp already defined in libc.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 "libc.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
libc.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Regedit.exe : fatal error LNK1120: 1 unresolved externals


网上查一下,说将USE MFC in a share dll  改成 USE MFC in a static dll

然后编译,更是失望

 

ibc.lib(crt0dat.obj) : error LNK2005: __cinit already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: _exit already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __exit already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __cexit already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __c_exit already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __C_Exit_Done already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __C_Termination_Done already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __exitflag already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __wpgmptr already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __pgmptr already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: ___winitenv already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __wenviron already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: ___initenv already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __environ already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: ___wargv already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: ___argv already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: ___argc already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __winminor already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __winmajor already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __winver already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __osver already defined in libcmtd.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __umaskval already defined in libcmtd.lib(crt0dat.obj)
libcmtd.lib(crt0init.obj) : warning LNK4098: defaultlib "libc.lib" conflicts with use of other libs; use /NODEFAULTLIB:library

 

于是改回USE MFC in a share dl,细细想一想,其实问题的原因上面已经指出,就是红色那一句,默认的"libc.lib"和其他的一些libs有冲突,可以用 /NODEFAULTLIB:library设置屏蔽掉默认的libcmtd.lib。

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

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

重新编译,链接,通过。

Linking...

Regedit.exe - 0 error(s), 0 warning(s)

 

链接错误出现时候,其实有时候编译器已经提供了足够的信息让我们判断哪里出错了。


你可能感兴趣的:(error LNK2005的解决)