如何解决 Visual Studio (LNK2005) 中的此链接错误?

发布于 2024-07-22 23:22:08 字数 579 浏览 4 评论 0原文

我一直遇到以下形式的链接器错误:

libcmtd.dll msvmrtd.dll 某些元素(例如: _mkdir ) 已经 定义...

但我不知道如何解决它们。

这是完整的错误消息:

私有:__thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) 已在中定义 LBCMTD.lib(typinfo.obj)

MSVCRTD.lib(ti_inst.obj):错误 LNK2005:“私有:类 type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) 已在中定义 LBCMTD.lib(typinfo.obj)

你能帮我解决这个问题吗?

I keep having linker errors of the following form:

libcmtd.dll msvmrtd.dll some element(ex: _mkdir ) already
defined...

and I don't know how to resolve them.

Here is a complete error message:

private: __thiscall type_info::type_info(class type_info const &)"
(??0type_info@@AAE@ABV0@@Z) already defined in
LIBCMTD.lib(typinfo.obj)

MSVCRTD.lib(ti_inst.obj) : 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)

Can you help me solve this issue?

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

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

发布评论

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

评论(4

天赋异禀 2024-07-29 23:22:08

检查几件事:

  1. 你的头文件是否受到保护。 也就是说,他们有#ifndef 防护装置。

  2. 您是否在标头中定义(非模板)函数而不使用 inline 关键字。 这会搞乱很多东西。

  3. 您是否尝试在 .cpp 文件中定义模板? 所有模板定义都需要位于标头中。

请发布一些代码和确切的错误文本!

Check a few things:

  1. Are your header files guarded. I.e. do they have #ifndef guards.

  2. Are you defining (non-template) functions in headers without the inline keyword. That messes lots of stuff up.

  3. Are you trying to define templates in a .cpp file. All template definitions need to be in headers.

Post some code and exact error text please!

子栖 2024-07-29 23:22:08

您的问题是您正在链接两个提供相同符号的文件。

您尚未提供真正的错误消息,因此我们无法准确告诉您问题是什么,但很可能您正在链接来自两个不同版本的 Visual Studio 的库。

还可以通过搜索网络找到可用的解决方案(我假设您这样做了,但只是错过了相关文章:-),建议您可以通过更改 “多线程调试(/MTd)”中的项目选项来解决问题““多线程调试 DLL (/MTD)” 但我还没有研究过这个。

请发布完整的错误,以便我们提供更有针对性的帮助。

Your problem is that you're linking with two files providing the same symbol.

You haven't provided the real error message so we can't tell you exactly what the problem is but it's likely to be that you're linking with libraries from two different versions of Visual Studio.

There are also solutions available by searching the web (I assume you did this but just missed the articles in question :-) that suggest you can fix the problem by changing the project options from "Multi-threaded Debug(/MTd)" to "Multi-threaded Debug DLL (/MTD)" but I haven't looked in to this.

Please post the complete error so we can offer more targeted assistance.

别再吹冷风 2024-07-29 23:22:08

确保为运行时库链接选择的选项对于每个项目和库都是相同的。
项目属性-> 配置属性-> C/C++-> 代码生成-> 运行时库 -> “多线程”/“多线程 DLL”/ ...

我的问题是我的所有 C++ 项目都是“多线程”,但我引用的是“多线程 DLL”的 Fortran 模块

Make sure the option you select for Runtime Libary linking is the same for every project and library.
Project Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library -> "Multi-threaded" / "Multi-threaded DLL" / ...

My issue was all of my C++ projects were "Multi-threaded" but I was referencing fortran modules that were "Multi-threaded DLL"

心的憧憬 2024-07-29 23:22:08

关于 LNK4098 的 MSDN 文章有一个非常有用的表:它告诉您哪些库需要手动添加到“忽略特定库”列表中,具体取决于您使用的 CRT。 您需要选择一个 CRT(是否多线程;静态或 DLL;调试或发布),然后根据您的选择添加忽略库。

KB154753 ... 程序在使用以下命令构建时将链接的库中更详细地描述了根本原因Visual C++

我对此的解释是,在某些情况下,自动选择链接代码的 CRT 库的算法将选择几个冲突的库。

The MSDN article on LNK4098 has a very useful table: it tells you which libraries to manually add to the "Ignore specific library" list, depending on which CRT you're using. You need to pick a CRT (Multithreaded or not; static or DLL; debug or release), and then add the ignore libraries based on your choice.

The underlying cause is described in more detail in KB154753 ... libraries that a program will link with when built by using Visual C++

My interpretation of this is that in certain situations the algorithm that automatically picks which CRT libraries to link your code with will pick several conflicting libraries.

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