简体   繁体   English

如何忽略LNK2005和LNK1169?

[英]how to ignore LNK2005 & LNK1169?

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. 所以我有一个使用外部库的Visual Studio 2010项目,为了在没有LNK2005的情况下进行编译,我不得不在链接器设置中处理库的顺序。

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. 我让它在发布模式下编译良好,但无论出于何种原因,我都无法在调试中没有LNK错误的情况下编译它。

Is there no way to generally ignore LNK2005 and tell the linker to simply use whatever he encounters first? 是否通常无法忽略LNK2005并告诉链接器只使用他遇到的任何内容?

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 因此,我正在寻找忽略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

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. 这篇MSDN文章提供了一些有关修复它的信息,以及链接以获取更多信息。

You may try the linker-option /FORCE (Force File Output in the Linker General tab of the Project Properties). 您可以尝试使用“项目属性”的“链接器常规”选项卡中的链接器选项/ FORCE(强制文件输出)。 This will force the linker to create a exe/dll even when such errors occur. 即使发生此类错误,这也会强制链接器创建exe / dll。 But its left to you to find out if this exe does work at all or even correctly. 但是它留给你去了解这个exe是否真的起作用或者甚至是正确的。 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. 这可能需要相当长的时间 - 有时候我花了一天多时间,但应该做得恰到好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM