views:

21

answers:

1

I'm integrating 3rd party code into my MFC app under Visual Studio 2010.
When 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 advice I was able to complete the build 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) many warnings are still reported. If I also add /NODEFAULTLIB:LIBCMT most of them are gone.

What is the cause of this?
How can I solve this, instead of working around it?

+2  A: 

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

You're fixing the right thing by saying /NODEFAULTLIB:LIBCMT. Does the debug/release flag on the third-party library that you're linking against match the debug/release mode on your app build? I would guess that the third-party code is pulling in a redundant library somehow.

sblom
I have the code for most of the 3rd party package. Where can I find the debug/release flag in there? Could it be in a compiled dll I might have with the package?
Jonathan