I am using Intel C++ 13.0.1.119 Build 20121008 for IA-32 running on Windows in Visual Studio 2012. I've been having issues with linker errors and have narrowed it down to the option /Qcheck-pointers:rw
. Whenever I compile with /Qcheck-pointers:rw
, I get the following errors:
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
I found this article, indicating that it could be solved by turning off checking for undimensioned arrays using /Qcheck-pointers-undimensioned-
. However, this seemed to have no effect, and I got the same linker errors.
Does anyone know how to fix this linking issue?
Update: As per Eric Shiyin Kang's suggestion, I left /Qcheck-pointers:rw
and /Qcheck-pointers-undimensioned-
on the command line, but added /NODEFAULTLIB:libcmt.lib
as a linker command. This resulted in me getting a different linker error:
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
Update 2: Here is the full compiler command line:
/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"
Here is the full linker command line:
/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
I am using the GTest library and am using the Multi-Threaded Debug runtime library, to match GTest.
Based on the discussion, and since you use a manually built library gtestd.lib
in your project of Project2.exe
, I think the problem is you are trying to pack different versions of C run-time lib such as libcmt.lib/libcmtd.lib
into your executable file Project2.exe
, either by static linking or by dynamic linking.
One is packed into gtestd.lib
by the option /MTd
in gtest project and then you are trying to pack gtestd.lib
into Project2.exe
.
The other one will be packed into Project2.exe
directly by /MTd
in the project of Project2.exe
.
The solution could be
1) use /MDd
,/MTd
,/MD
or /MTd
constantly in all the projects involved, or
2) don't link any external libraries in, when building a static/dynamic library such as gtest.lib
, by using /NODEFAULTLIB
or /NODEFAULTLIB:<name_of_some_of_def_libs>
. And only link those libs when building the executable files.