how to ignore LNK2005 & LNK1169?

Mat picture Mat · Nov 3, 2010 · Viewed 9.9k times · Source

So I have a Visual Studio 2010 project that uses external libraries and in order to get it compile without LNK2005 I had to juggle arround with the order of the libraries in the linker settings.

I got it to compile fine in release mode, but for whatever reasons I don't manage to get it to compile without LNK errors in debug.

Is there no way to generally ignore LNK2005 and tell the linker to simply use whatever he encounters first?

Thanks!

//edit: here are some of the errors output of the PARTICULAR problem. however I already tried to solve that in different ways with each solution giving me different linker problems. hence i'm looking for general solution to ignore LNK2005

Error 7 error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in Libcmtd.lib(typinfo.obj) ...\msvcprtd.lib(MSVCP100D.dll)

Error 8 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) ...\msvcprtd.lib(MSVCP100D.dll)

Error 9 error LNK2005: _exit already defined in Libcmtd.lib(crt0dat.obj) ...\msvcprtd.lib(MSVCP100D.dll)

Error 10 error LNK2005: __invalid_parameter already defined in Libcmtd.lib(invarg.obj) ...\msvcprtd.lib(MSVCP100D.dll)

...

Error 37 error LNK1169: one or more multiply defined symbols found

Answer

Eli Bendersky picture Eli Bendersky · Nov 3, 2010

You absolutely must not ignore linker errors, ever! A linker is telling you that it's confused about a symbol that's defined in multiple places - where should it take the definition from? Do you really want it to be arbitrary? What about when you change your code and the linker randomly decides to take the other definition which might suddenly break your code?

Instead of fighting the tool, correct your code so that it compiles and links without errors. This MSDN article has some information on fixing it, along with links for more information.