VC里引用第三方库常遇到的链接重复定义问题

Runtime
Library是个很糟糕的问题,假设你设计了一个库,这个使用的Runtime
Library是单线程库(/ML)或是单线程Debug库(/MLd),然后你在MFC项目中使用多线程库(/MD)或多线程Debug库(/
MDd)。

就会出现大量链接错误:
LIBCMT.lib(setlocal.obj) : error LNK2005: _setlocale already defined
in
MSVCRT.lib(MSVCRT.dll)
LIBCMT.lib(tolower.obj) : error LNK2005: _tolower already defined in
MSVCRT.lib(MSVCRT.dll)
LIBCMT.lib(dosmap.obj) : error LNK2005: __errno already defined in
MSVCRT.lib(MSVCRT.dll)
LIBCMT.lib(osfinfo.obj) : error LNK2005: __get_osfhandle already
defined
in MSVCRT.lib(MSVCRT.dll)
LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in
MSVCRT.lib(MSVCRT.dll)
LIBCMT.lib(strftime.obj) : error LNK2005: _strftime 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(tzset.obj) : error LNK2005: __tzset already defined in
MSVCRT.lib(MSVCRT.dll)
LIBCMT.lib(getenv.obj) : error LNK2005: _getenv already defined in
MSVCRT.lib(MSVCRT.dll)
MSVCRT.lib(MSVCRT.dll) : error LNK2005: __strdup already defined in
LIBCMT.lib(strdup.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: __close already defined in
LIBCMT.lib(close.obj)
LIBCMT.lib(setlocal.obj) : warning LNK4006: _setlocale already defined
in MSVCRT.lib(MSVCRT.dll); second definition ignored
LIBCMT.lib(tolower.obj) : warning LNK4006: _tolower already defined in
MSVCRT.lib(MSVCRT.dll); second definition ignored
LIBCMT.lib(dosmap.obj) : warning LNK4006: __errno already defined in
MSVCRT.lib(MSVCRT.dll); second definition ignored
LIBCMT.lib(osfinfo.obj) : warning LNK4006: __get_osfhandle already
defined in MSVCRT.lib(MSVCRT.dll); second definition ignored
LIBCMT.lib(crt0dat.obj) : warning LNK4006: _exit already defined in
MSVCRT.lib(MSVCRT.dll); second definition ignored
LIBCMT.lib(strftime.obj) : warning LNK4006: _strftime already defined
in
MSVCRT.lib(MSVCRT.dll); second definition ignored
LIBCMT.lib(crt0init.obj) : warning LNK4006: ___xc_z already defined in
MSVCRT.lib(cinitexe.obj); second definition ignored
LIBCMT.lib(crt0init.obj) : warning LNK4006: ___xc_a already defined in
MSVCRT.lib(cinitexe.obj); second definition ignored
LIBCMT.lib(crt0init.obj) : warning LNK4006: ___xi_z already defined in
MSVCRT.lib(cinitexe.obj); second definition ignored
LIBCMT.lib(crt0init.obj) : warning LNK4006: ___xi_a already defined in
MSVCRT.lib(cinitexe.obj); second definition ignored
LIBCMT.lib(tzset.obj) : warning LNK4006: __tzset already defined in
MSVCRT.lib(MSVCRT.dll); second definition ignored
LIBCMT.lib(getenv.obj) : warning LNK4006: _getenv already defined in
MSVCRT.lib(MSVCRT.dll); second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: __strdup already defined in
LIBCMT.lib(strdup.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: __close already defined in
LIBCMT.lib(close.obj); second definition ignored
   Creating library ../Release/php4nts.lib and object
../Release/php4nts.exp
LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of
other
libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of
other
libs; use /NODEFAULTLIB:library
LINK : warning LNK4049: locally defined symbol "_pcre_free" imported
LINK : warning LNK4049: locally defined symbol "_pcre_malloc" imported
resolv.lib(res_send.obj) : error LNK2001: unresolved external symbol
_writev
LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
../Release/php4nts.dll : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

这就是你所用的库所使用的链接库和项目使用的链接库不同所出现的问题。

把两个都设成
/ML(/MLd),或/MD(/MDd)。删掉旧的对象文件,重新编译就能通过。

你可能感兴趣的:(VC里引用第三方库常遇到的链接重复定义问题)