5

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

RED SOFT ADAIR
  • 12,032
  • 10
  • 54
  • 92
Mat
  • 63
  • 1
  • 1
  • 5
  • I have no clue what you're talking about. GNU ld does not have these "LNK2005" and "LNK1169". – Ignacio Vazquez-Abrams Nov 03 '10 at 07:52
  • can you please show us some more of the error messages you get? – Chubsdad Nov 03 '10 at 07:54
  • sorry, added the info that i'm working on Visual Studio – Mat Nov 03 '10 at 07:55
  • @Ignacio -> He's talking about Visual C++ – Moo-Juice Nov 03 '10 at 07:56
  • @Chubsdad - I added some of the linker errors. however, the LNK2005 errors are different with each solution i tried so far. so far i tried to juggle arround the libary order in the linker settings, to use DLL version of multithreaded MFC instead of static, to use releasebuild of the external library instead of debugbuild – Mat Nov 03 '10 at 08:04

2 Answers2

11

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.

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
  • 2
    but most probably the definitions are equivalent anyway, no? or maybe my actual program will work with either definition because it doesn't actually make use of functionality dependant upon it - so there's good chance that it's going to work - i just need it to run to test something - and as i said i already read and tried various fixes to the problem – Mat Nov 03 '10 at 08:14
  • 4
    @Mat: "most probably" and "good chance" are concepts not suitable for programming. The linker is a computer program, a dumb, obedient entity that has to know exactly what its inputs are. Fixing the linker errors is exactly what you need to do to make it work. Perhaps you want to ask a new SO question on *how to fix* you project, explaining in detail the exact layout of your libs, DLLs and project settings. It's best to bring this to some minimal setup that fails, however. – Eli Bendersky Nov 03 '10 at 08:18
  • but they are suitable if i just want to get something to run to test it. this is not something i'm going to publish or want to waste much more time on it - i just need it to run – Mat Nov 03 '10 at 08:18
  • @Mat: I have nothing more to add, except that you can have a good feel about the quality of your question, 50 minutes after its posting, by the comments and answers you received – Eli Bendersky Nov 03 '10 at 08:42
  • 1
    @Mat: You really should take some time to learn how to fix this correctly. Perhaps this project isn't meant to be published but hiding the errors is **never** a good solution. Sadly, the world is already full of lazy people, don't become another one. – ereOn Nov 03 '10 at 08:48
  • i'd say if something needs to work the other day i'm absolutely fine with "whatever works" – Mat Nov 03 '10 at 09:13
  • @Mat - As a good programmer you shouldn't ignore even compiler warnings. Linker warnings must be a strict no no and should be fixed compulsorily. – DumbCoder Nov 03 '10 at 12:57
  • 2
    @Mat So long as you're fine with "whatever works in the short term and may break unpredictably in the future", go nuts. But why would you ask a question of SO and then ignore all the expert advice you don't want to hear? – user229044 Apr 15 '11 at 16:37
11

You may try the linker-option /FORCE (Force File Output in the Linker General tab of the Project Properties). This will force the linker to create a exe/dll even when such errors occur. But its left to you to find out if this exe does work at all or even correctly. After all i would not recommend this strategy.

Linker errors can sometimes be tedious to solve, but usually it has to be done only after migrating or setting up a project. This may take quite a while - it sometimes took me more then a day, but it should be done properly.

RED SOFT ADAIR
  • 12,032
  • 10
  • 54
  • 92
  • Thank you so much - this is exactly the answer to my question and works for my problem like a charm! headache-free! – Mat Nov 03 '10 at 09:12