Reputation: 10137
I know: this has already been addressed, but after reading as much as I could about this I still haven't been able to figure out why I haven't been able to fix it, or what to fix even.
You see, according to this, there will be issues if your project is using two different standard run-time libraries for compilation at the same time. The most common of these appear to be libcmt.lib and msvcrt.lib, along with their debugging equivalents.
Apparently, my project is using both of these, hence the following warnings which appear together:
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>glew32s.lib(glew.obj) : warning LNK4099: PDB 'vc100.pdb' was not found with 'glew32s.lib(glew.obj)' or at 'C:\Programming\VS\Play_VS\Debug\vc100.pdb'; linking object as if no debug info
As you can see, I'm using glew for this. The code compiles without any errors, but the fact that the only external libraries I'm using are GLEW/GLFW/GLU/GLM makes me wonder if there is any configuration issues which might reside in my current build. I'm not using MFC or ATL or any other Visual C++ library apart from their native STL implementation.
First off, I'll say that I've tried setting my project's properties from Multi-Threaded [Debug] DLL
to Multi-Threaded [Debug]
, which seems to make things worse by producing the following output:
1>MSVCRT.lib(MSVCR110.dll) : error LNK2005: _free already defined in LIBCMTD.lib(dbgfree.obj)
1>MSVCRT.lib(MSVCR110.dll) : error LNK2005: _malloc already defined in LIBCMTD.lib(dbgmalloc.obj)
1>MSVCRT.lib(MSVCR110.dll) : error LNK2005: _fprintf already defined in LIBCMTD.lib(fprintf.obj)
1>MSVCRT.lib(MSVCR110.dll) : error LNK2005: ___iob_func already defined in LIBCMTD.lib(_file.obj)
1>MSVCRT.lib(MSVCR110.dll) : error LNK2005: _strchr already defined in LIBCMTD.lib(strchr.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 LIBCMTD.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 LIBCMTD.lib(typinfo.obj)
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>C:\Programming\VS\Play_VS\Debug\Play_VS.exe : fatal error LNK1169: one or more multiply defined symbols found
Likewise, looking through my compilation flags for both Debug and Release builds tells me that /MT
(libcmt.lib) does not exist in either of the command generation inputs. As far as I know, most people writing native C++ applications in windows use /MD
, i.e. msvcrt.lib
.
Debug Build Input
/GS /analyze- /W3 /Zc:wchar_t /ZI /Gm /Od /Fd"Debug\vc110.pdb" /fp:precise /D "GLEW_STATIC" /D "_CRT_SECURE_NO_WARNINGS" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /RTC1 /GR /Gd /Oy- /MDd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\Play_VS.pch"
Release Build Input
/GS /GL /analyze- /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /Fd"Release\vc110.pdb" /fp:precise /D "_CRT_SECURE_NO_WARNINGS" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MD /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\Play_VS.pch"
How can I fix this? I appreciate the help.
Upvotes: 2
Views: 4702
Reputation: 552
You are mixing code that was compiled with /MD (use DLL version of CRT) with code that was compiled with /MT (use static CRT library). That cannot work, all source code files must be compiled with the same setting. Given that you use libraries that were pre-compiled with /MD, almost always the correct setting, you must compile your own code with this setting as well.
Project + Properties, C/C++, Code Generation, Runtime Library.
Beware that these libraries were probably compiled with an earlier version of the CRT, msvcr100.dll is quite new. Not sure if that will cause trouble, you may have to prevent the linker from generating a manifest. You must also make sure to deploy the DLLs you need to the target machine, including msvcr100.dll
there's a same problem: error LNK2005: xxx already defined in MSVCRT.lib(MSVCR100.dll) C:\something\LIBCMT.lib(setlocal.obj)
Upvotes: 1