鲜花过多!

我一直在使用Visual Studio 2010开发静态链接的应用程序(嗯,它是跨平台的,但这只是Windows问题)。

在为Debug配置设置链接方面,我遇到的问题很少,因此我没想到很难更改它以创建Release配置,但是经过一个下午的工作,它仍然让我望而却步。尝试为NODEFAULTLIB设置各种值会导致“无法解析的外部符号”错误或“已定义”错误,有时还会同时出现。

从我的笔记中,我尝试过NODEFAULTLIB-LIBCMT,MSVCRT,MSVCPRT或根本不尝试,每次都具有不同的结果(有关详细信息,请参见下文)。

现在,我的Debug配置使用/NODEFAULTLIB:MSVCRTD/NODEFAULTLIB:MSVCPRTD并且可以正常工作,因此您认为/NODEFAULTLIB:MSVCRT/NODEFAULTLIB:MSVCPRT适用于Release配置。而且事实并非如此,这对我来说是个危险信号...

我正在与其他几个库建立链接-我非常谨慎地系统地确保从Debug到Release时它们被视为完全相同,但是可以想象这是一个问题,如果可以的话,如何系统地对其进行跟踪?

感谢您的宝贵时间!

在“链接器/命令行”属性页中,“所有选项”为:

 /OUT:".\Release\SlowGold 8.exe" /NOLOGO "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:".\Release\SlowGold 8.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /PDB:".\Release\SlowGold 8.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /PGD:"C:\development\rec-vs\rec\projects\slow\Builds\VisualStudio2010\Release\SlowGold 8.pgd" /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

其他选项是:
/LIBPATH:..\\..\\..\\..\\externals\\rubberband\\win32\\ipp\\common ippacemerged.lib ippacmerged.lib ippcorel.lib ippsemerged.lib ippsmerged.lib ippsremerged.lib ippsrmerged.lib /LIBPATH:..\\..\\..\\..\\externals\\rubberband\\win32\\ipp\\release\\static rubberband-library.lib /LIBPATH:..\\..\\..\\..\\..\\glog\\Release libglog_static.lib /LIBPATH:..\\..\\..\\..\\..\\mpg123\\ports\\MSVC++\\2008\\Release libmpg123.lib /LIBPATH:..\\..\\..\\..\\..\\protobuf\\vsprojects\\Release libprotobuf.lib

这是各种/NODEFAULTLIB:值的一些错误消息。

迄今为止最好的:/NODEFAULTLIB:LIBCMT
1>------ Build started: Project: Slow, Configuration: Release Win32 ------
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::basic_ostream<char,struct std::char_traits<char> >(class std::basic_streambuf<char,struct std::char_traits<char> > *,bool)" (??0?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits@D@std@@@1@_N@Z) already defined in libcpmt.lib(cerr.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
1>.\Release\SlowGold 8.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

仅使用/NODEFAULTLIB:MSVCRT的另一种尝试
1>------ Build started: Project: Slow, Configuration: Release Win32 ------
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::basic_ostream<char,struct std::char_traits<char> >(class std::basic_streambuf<char,struct std::char_traits<char> > *,bool)" (??0?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits@D@std@@@1@_N@Z) already defined in libcpmt.lib(cerr.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp__strncat
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp__perror
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp___pclose
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl _open(char const *,int,int)" (__imp_?_open@@YAHPBDHH@Z)
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp___access
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp___popen
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp___wassert
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp__fdopen
1>OLDNAMES.lib(fdopen.obi) : error LNK2001: unresolved external symbol __imp__fdopen
1>libglog_static.lib(logging.obj) : error LNK2001: unresolved external symbol __imp__unlink
1>OLDNAMES.lib(unlink.obi) : error LNK2001: unresolved external symbol __imp__unlink
1>libglog_static.lib(utilities.obj) : error LNK2001: unresolved external symbol __imp___getpid
1>libglog_static.lib(port.obj) : error LNK2001: unresolved external symbol __imp___vsnprintf
1>libprotobuf.lib(message.obj) : error LNK2001: unresolved external symbol __imp__ldiv
1>libprotobuf.lib(descriptor.obj) : error LNK2001: unresolved external symbol __imp__ldiv
1>libprotobuf.lib(extension_set.obj) : error LNK2001: unresolved external symbol __imp__ldiv
1>libprotobuf.lib(common.obj) : error LNK2001: unresolved external symbol __imp___snprintf
1>libprotobuf.lib(strutil.obj) : error LNK2001: unresolved external symbol __imp___snprintf
1>OLDNAMES.lib(fdopen.obi) : error LNK2001: unresolved external symbol __imp___fdopen
1>OLDNAMES.lib(unlink.obi) : error LNK2001: unresolved external symbol __imp___unlink
1>.\Release\SlowGold 8.exe : fatal error LNK1120: 15 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

没有/NODEFAULTLIB:
1>------ Build started: Project: Slow, Configuration: Release Win32 ------
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::basic_ostream<char,struct std::char_traits<char> >(class std::basic_streambuf<char,struct std::char_traits<char> > *,bool)" (??0?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits@D@std@@@1@_N@Z) already defined in libcpmt.lib(cerr.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __stricmp already defined in LIBCMT.lib(stricmp.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strerror_s already defined in LIBCMT.lib(strerror.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fflush already defined in LIBCMT.lib(fflush.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strtol already defined in LIBCMT.lib(strtol.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strrchr already defined in LIBCMT.lib(strrchr.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __write already defined in LIBCMT.lib(write.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __close already defined in LIBCMT.lib(close.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _memmove already defined in LIBCMT.lib(memmove.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _printf already defined in LIBCMT.lib(printf.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fprintf already defined in LIBCMT.lib(fprintf.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: ___iob_func already defined in LIBCMT.lib(_file.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _abort already defined in LIBCMT.lib(abort.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _memchr already defined in LIBCMT.lib(memchr.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __strtoi64 already defined in LIBCMT.lib(strtoq.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __strtoui64 already defined in LIBCMT.lib(strtoq.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strtoul already defined in LIBCMT.lib(strtol.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __errno already defined in LIBCMT.lib(dosmap.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strerror already defined in LIBCMT.lib(strerror.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strchr already defined in LIBCMT.lib(strchr.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _sprintf already defined in LIBCMT.lib(sprintf.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strtod already defined in LIBCMT.lib(strtod.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strpbrk already defined in LIBCMT.lib(strpbrk.obj)
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __read already defined in LIBCMT.lib(read.obj)
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>.\Release\SlowGold 8.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

最佳答案

汉斯·帕桑特(Hans Passant)在对我的问题的评论中向我提供了解决方案的关键!如果他回来并用他们作为答案,我会抹掉它,并把他归功于...

如预期的那样,其中一个第三方库在发行版中未设置为/MT(但在调试中为/MTd)-更改该标志可使它全部正常工作。

您可以在“属性”-“C/C++”-“代码生成”-“运行时库”中找到该选项。

10-08 07:36