Visual Studio - LNK2005 error in debug mode

I integrate third-party code into my MFC application in Visual Studio 2010.
In Debug mode, the following build error occurs:

1>LIBCMT.lib(invarg.obj) : error LNK2005: __initp_misc_invarg 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: __set_invalid_parameter_handler 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: __invoke_watson 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: __invalid_parameter already defined in libcmtd.lib(invarg.obj) 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: ___pInvalidArgHandler already defined in libcmtd.lib(invarg.obj) 1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library 1>D:\My Documents\Dev\MyProject\MyProject\Debug\MyProject.exe : fatal error LNK1169: one or more multiply defined symbols found 

Using this tip, I was able to complete the assembly in two ways:

  • In release mode
  • In debug mode using / FORCE: MULTIPLE as an additional linker command line option

In the second case (debug mode) all messages are still being reported. If I also add / NODEFAULTLIB: LIBCMT, most of them are gone.

What is the reason for this? How can I solve this and not work around it?

+4
source share
3 answers

For some reason, you are contacting LIBCMT and LIBCMTD (debug version). (From reading the end of each line of the error: already defined in libcmtd.lib(invarg.obj) )

You correct the right thing by saying / NODEFAULTLIB: LIBCMT. Is the debug / release flag in the third-party library that you link enabled with the debug / release mode in your application build? I suppose third-party code is somehow pulling out a redundant library.

+10
source

If you're lucky, your third-party package contains xxx.lib, as well as xxxD.lib, as for LIBCMT. Then you just need to link the corresponding release / debug version. Worked for me in a similar case.

0
source

I solved the same problem as follows: In Solution Explorer> Configuration Settings> C / C ++> Code Generation. In the Runtime Library field, select .... for my "third-party code" I had to select Multi-threaded (/ MTd) and it worked.

0
source

All Articles