在 MSVC++2010 中使用静态链接在调试配置中编译 DLL 时出现链接器错误

发布于 2024-11-29 14:01:42 字数 455 浏览 1 评论 0原文

我想尝试使用 /MTd 链接器选项而不是 /MDd 来调试我的 DLL 项目。我对发布版本使用静态链接。在调试配置中,我收到链接器错误:

break.obj : error LNK2005: 
"public: void __thiscall std::_Container_base12::_Orphan_all(void)"
(?_Orphan_all@_Container_base12@std@@QAEXXZ)
is already defined in msvcprtd.lib(MSVCP100D.dll).

总共有 5 个类似的错误,所有 LNK2005 在 break.obj 中,都提到了这个 base12 的东西。 break.obj 是按字母顺序排列的第一个文件,因此其他文件可能也会出现问题。我没有在此文件中定义任何具有此名称的函数。那里发生了什么事?

I would like to try the /MTd linker option instead of /MDd for a debug build of my DLL project. I use static linking for Release builds. In the Debug configuration, I get linker errors:

break.obj : error LNK2005: 
"public: void __thiscall std::_Container_base12::_Orphan_all(void)"
(?_Orphan_all@_Container_base12@std@@QAEXXZ)
is already defined in msvcprtd.lib(MSVCP100D.dll).

There are a total of 5 similar errors, all LNK2005 in break.obj, all mentioning this base12 thing. break.obj is the alphabetically first file so maybe the problem would occur with other files as well. I don't define any function with this name in this file. What's happening there?

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

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

发布评论

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

评论(1

怀念你的温柔 2024-12-06 14:01:42

也许发布一些构建日志 - 某些原因导致 DLL 运行时处于链接步骤中。

确保清理所有内容并执行完整重建。如果这没有帮助,请确保一个或多个源文件没有任何文件级项目设置,这可能会导致它被重建以链接到 DLL 运行时。据我所知,没有简单的方法可以从 IDE 中识别此类文件级覆盖。直接在文本编辑器中查看构建日志或 .vcxproj 文件可能有助于缩小范围。如果查看 .vcxproj 文件,具有项目覆盖的源文件将在文件的 元素中包含用于覆盖设置的 XML 元素,其中大多数 元素将没有子元素。

最后,如果它不是太大,您可能想看看从头开始重新创建项目是否有帮助(我知道这很激烈并且没有必要,但有时它有助于消除怪异)。


作为旁注,MSDN 说 (http://msdn.microsoft.com /en-us/library/abx4dbyh.aspx):

由于通过链接到静态 CRT 构建的 DLL 将具有自己的 CRT 状态,因此不建议静态链接到 DLL 中的 CRT,除非特别需要并理解这样做的后果。

顺便说一句,_Container_base12 是一种用于迭代器检查/调试的类型 - 这就是为什么您不能直接在任何源文件中看到它或其任何成员函数。您应该确保您没有对 _HAS_ITERATOR_DEBUGGING_SECURE_SCL 宏设置执行任何错误操作。但我认为这与您的具体问题没有任何关系。如果您最终认为它们与您的问题有关,您可能需要查看:

Maybe post some of the build log - something is causing the DLL runtime to be in the link step.

Make sure you clean everything and perform a full rebuild. If that doesn't help, make sure there aren't any file-level project settings for one or more source files, which might be cause it to be rebuilt to link against the DLL runtime. As far as I know there's no easy way to identify such file-level overrides form the IDE. Looking at the build logs or the .vcxproj file directly in a text editor might help with narrowing that down. If you look in the .vcxproj file, a source file with project overrides will have XML elements for the overridden settings in the file's <ClCompile> element, where most <ClCompile> elements will have no sub-elements.

Finally, if it's not too big, you may want to see if recreating the project from scratch helps (I know it's drastic and shouldn't be necessary, but sometimes it helps get rid of weirdness).


As a side-note, MSDN says (http://msdn.microsoft.com/en-us/library/abx4dbyh.aspx):

Because a DLL built by linking to a static CRT will have its own CRT state, it is not recommended to link statically to the CRT in a DLL unless the consequences of this are specifically desired and understood.

By the way, _Container_base12 is a type used for iterator checking/debugging - that's why you don't see it or any of its member functions directly in any of your source files. You should make sure you aren't doing anything incorrect with the _HAS_ITERATOR_DEBUGGING and _SECURE_SCL macro settings. But I don't think that has anything to do with your specific specific problem. If you end up thinking they related to your problem, you might want to check out:

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