2

我正在使用 Intel C++ 13.0.1.119 Build 20121008 for IA-32 在 Visual Studio 2012 的 Windows 上运行。我一直遇到链接器错误问题,并将其缩小到选项/Qcheck-pointers:rw。每当我使用 编译时/Qcheck-pointers:rw,都会出现以下错误:

1>  xilink: executing 'link'
1>libcmt.lib(invarg.obj) : error LNK2005: "void __cdecl _invalid_parameter(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned int)" (?_invalid_parameter@@YAXPBG00II@Z) already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: "void __cdecl _invoke_watson(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned int)" (?_invoke_watson@@YAXPBG00II@Z) already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __call_reportfault already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __get_invalid_parameter_handler already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __initp_misc_invarg already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __invalid_parameter already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __set_invalid_parameter_handler already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: ___pInvalidArgHandler already defined in LIBCMTD.lib(invarg.obj)
1>libcpmtd.lib(xdebug.obj) : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>Y:\...\ : fatal error LNK1169: one or more multiply defined symbols found

我找到了这篇文章,表明它可以通过关闭检查无维数组使用来解决/Qcheck-pointers-undimensioned-。但是,这似乎没有任何效果,并且我得到了相同的链接器错误。

有谁知道如何解决这个链接问题?

更新:根据 Eric Shiyin Kang 的建议,我离开/Qcheck-pointers:rw/Qcheck-pointers-undimensioned-在命令行上,但添加/NODEFAULTLIB:libcmt.lib为链接器命令。这导致我得到一个不同的链接器错误:

1>  xilink: executing 'link'
1>libcpmt.lib(nothrow.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in libcpmtd.lib(stdthrow.obj)
1>libcpmt.lib(nothrow.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MTd_StaticDebug' in libcpmtd.lib(stdthrow.obj)
1>Y:\..\.exe : fatal error LNK1319: 2 mismatches detected

更新 2: 这是完整的编译器命令行:

/RTCc /GS /Qcheck-pointers:rw /debug:expr-source-pos /W5 /Gy /Zc:wchar_t /I"\..\include\gtest" /I"\..\include\" /Zi /Od /Qintel-extensions- /Fd"Debug\vc110.pdb" /fp:precise /D "_VARIADIC_MAX=10" /D "_MBCS" /Qipo /Zc:forScope /RTC1 /Qcheck-pointers-undimensioned- /Gd /MTd /Fa"Debug\" /EHsc /nologo /Za /Fo"Debug\" /Fp"Debug\Project2.pch" 

这是完整的链接器命令行:

/OUT:"\..\Project2.exe" /MANIFEST /NXCOMPAT /PDB:"\..\Project2.pdb" /DYNAMICBASE "gtestd.lib" "gtest_maind.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X86 /OPT:REF /SAFESEH / /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\Project2.exe.intermediate.manifest" /OPT:ICF /NOLOGO /LIBPATH:"\..\include\gtest\debug_build" /TLBID:1 /NODEFAULTLIB:libcmt.lib

我正在使用 GTest 库并正在使用多线程调试运行时库来匹配 GTest。

4

1 回答 1

5

基于讨论,并且由于您gtestd.lib在项目中使用手动构建的库Project2.exe,我认为问题是您试图通过静态链接或动态将不同版本的 C 运行时库打包libcmt.lib/libcmtd.lib到可执行文件中Project2.exe链接。

一个由 gtest 项目gtestd.lib中的选项/MTd打包,然后您尝试打包gtestd.libProject2.exe.

另一个将直接打包到Project2.exe项目/MTdProject2.exe

解决方案可能是

1)在所有涉及的项目中使用/MDd, /MTd,/MD或不断地使用,或/MTd

2)在构建静态/动态库时,不要链接任何外部库,例如gtest.lib,通过使用/NODEFAULTLIB/NODEFAULTLIB:<name_of_some_of_def_libs>。并且仅在构建可执行文件时链接这些库。

于 2013-01-25T17:11:11.613 回答