[置顶] 关于静态链接到MFC的项目链接时LIBCMTD.lib中符号重定义问题的处理方法libcmt.lib

  有时候为了软件的移植问题,我们需要将项目设置成静态链接到MFC配置,然而,编译通过,链结时常常出现这样的问题,

msvcrt.lib(MSVCRT.dll) : error LNK2005: _gmtime already defined in libcmt.lib(gmtime.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _atoi already defined in libcmt.lib(atox.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strchr already defined in libcmt.lib(strchr.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strstr already defined in libcmt.lib(strstr.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _free already defined in libcmt.lib(free.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _atol already defined in libcmt.lib(atox.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _realloc already defined in libcmt.lib(realloc.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _malloc already defined in libcmt.lib(malloc.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _time already defined in libcmt.lib(time.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strncmp already defined in libcmt.lib(strncmp.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _tolower already defined in libcmt.lib(tolower.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strtol already defined in libcmt.lib(strtol.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: __errno already defined in libcmt.lib(dosmap.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _mktime already defined in libcmt.lib(mktime.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _localtime already defined in libcmt.lib(localtim.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _memmove already defined in libcmt.lib(memmove.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strrchr already defined in libcmt.lib(strrchr.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _exit already defined in libcmt.lib(crt0dat.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: __strnicmp already defined in libcmt.lib(strnicmp.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: __stricmp already defined in libcmt.lib(stricmp.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: __strdup already defined in libcmt.lib(strdup.obj)
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _gmtime already defined in libcmt.lib(gmtime.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _atoi already defined in libcmt.lib(atox.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _strchr already defined in libcmt.lib(strchr.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _strstr already defined in libcmt.lib(strstr.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _free already defined in libcmt.lib(free.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _atol already defined in libcmt.lib(atox.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _realloc already defined in libcmt.lib(realloc.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _malloc already defined in libcmt.lib(malloc.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _time already defined in libcmt.lib(time.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _strncmp already defined in libcmt.lib(strncmp.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _tolower already defined in libcmt.lib(tolower.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _strtol already defined in libcmt.lib(strtol.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: __errno already defined in libcmt.lib(dosmap.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _mktime already defined in libcmt.lib(mktime.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _localtime already defined in libcmt.lib(localtim.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _memmove already defined in libcmt.lib(memmove.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _strrchr already defined in libcmt.lib(strrchr.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: _exit already defined in libcmt.lib(crt0dat.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: __strnicmp already defined in libcmt.lib(strnicmp.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: __stricmp already defined in libcmt.lib(stricmp.obj); second definition ignored
msvcrt.lib(MSVCRT.dll) : warning LNK4006: __strdup already defined in libcmt.lib(strdup.obj); second definition ignored

这时候,我们可以这样处理,将运行时库改成多线程DLL方式,修改以后再次链接,出现如下问题:

nafxcw.lib(nolib.obj) : warning LNK4098: defaultlib "mfc42.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
nafxcw.lib(nolib.obj) : warning LNK4098: defaultlib "mfcs42.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc
nafxcw.lib(filelist.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcw.lib(timecore.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcw.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype
Release/YiNuoHttpCMD.dll : fatal error LNK1120: 3 unresolved externals

这时我们可以这样处理,在预处理器上定义加上_AFXDLL,再链接,一切OK了

你可能感兴趣的:(多线程,mfc,dll)