how to ignore LNK2005 & LNK1169?

社会主义新天地 提交于 2019-12-01 03:35:56

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4085050/how-to-ignore-lnk2005-lnk1169

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!