如何忽略LNK2005 & LNK1169?

发布于 2024-09-30 01:59:29 字数 1030 浏览 14 评论 0原文

因此,我有一个使用外部库的 Visual Studio 2010 项目,为了在没有 LNK2005 的情况下编译它,我必须在链接器设置中调整库的顺序。

我让它在发布模式下编译得很好,但出于某种原因,我无法在调试中没有 LNK 错误的情况下编译它。

有没有办法普遍忽略 LNK2005 并告诉链接器简单地使用他首先遇到的任何内容?

谢谢!

//编辑:这里是特定问题的一些错误输出。但是我已经尝试以不同的方式解决这个问题,每个解决方案都会给我带来不同的链接器问题。因此我正在寻找通用解决方案来忽略 LNK2005

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

错误 8 错误 LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@ @AAEAAV0@ABV0@@Z) 已在 Libcmtd.lib(typinfo.obj) 中定义 ...\msvcprtd.lib(MSVCP100D.dll)

错误 9 错误 LNK2005: _exit 已在 Libcmtd.lib(crt0dat.obj) 中定义 ...\msvcprtd.lib(MSVCP100D.dll)

错误 10 错误 LNK2005: __invalid_parameter 已在 Libcmtd.lib(invarg.obj) 中定义 ...\msvcprtd.lib(MSVCP100D.dll)

...

错误 37 错误 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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

手心的海 2024-10-07 01:59:29

您可以尝试链接器选项 /FORCE(在项目属性的链接器常规选项卡中强制文件输出)。即使发生此类错误,这也会强制链接器创建 exe/dll。但这个 exe 是否能正常工作,甚至是否正确,需要您自己来判断。毕竟我不会推荐这个策略。

链接器错误有时解决起来很乏味,但通常只有在迁移或设置项目后才能完成。这可能需要相当长的时间——有时我花了一天多的时间,但应该正确完成。

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.

梦亿 2024-10-07 01:59:29

您绝对不能忽略链接器错误!链接器告诉您它对在多个位置定义的符号感到困惑 - 它应该从哪里获取定义?你真的希望它是任意的吗?当您更改代码并且链接器随机决定采用其他定义(这可能会突然破坏您的代码)时该怎么办?

不要与该工具对抗,而是更正您的代码,使其编译和链接没有错误。 这篇 MSDN 文章提供了一些有关修复该问题的信息,以及以下链接:更多信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文