VS2010 调试级别不匹配

发布于 2024-10-08 08:42:33 字数 263 浏览 1 评论 0原文

我在测试我的库时注意到,如果我在项目处于调试模式时尝试链接到在发布模式下构建的静态库,VS2010 将抛出错误。 相反,如果我尝试将 Debug 中构建的库与 Release 中构建的项目链接到。

错误 LNK2038:检测到“_ITERATOR_DEBUG_LEVEL”不匹配:值“0”与 Main.obj 中的值“2”不匹配

有没有办法绕过这种奇怪的行为?我是否只需分发两个版本的库?另外,为什么会出现这种情况呢?

I noticed while testing my library that VS2010 will throw an error if I try to link to a static library built in Release mode when the project is in Debug mode. Inversely, it appears that the same thing happens if I try to link to a library built in Debug with a project built in Release.

error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in Main.obj

Is there a way to bypass this strange behavior? Do I just have to distribute two versions of my library? In addition, why does this happen in the first place?

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

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

发布评论

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

评论(2

生死何惧 2024-10-15 08:42:33

这不是一个奇怪的行为,编译器根据宏定义、优化和其他标志创建不同的图像。最好不要分发静态库,因为用户必须拥有完全相同的编译器版本、标准库版本、相同的编译器标志,否则您将面临不兼容的风险:有时会出现链接错误,有时应用程序会崩溃,有时会表现不正确。

It's not a strange behavior, compiler creates different images depending on macro defines, optimization and other flags. It's better not to distribute static libraries, because the users will have to have exactly the same compiler version, standard library version, same compiler flags or you risk incompatibilities: sometimes you get linking errors, sometimes the application will crash, sometimes it will behave incorrectly.

衣神在巴黎 2024-10-15 08:42:33

库作者没有很好的选择来指出混合和匹配不起作用。它们必须触发链接器错误,这总是很棘手且令人困惑。这里不起作用的是,您不能将使用启用迭代器调试的 STL 类的库与禁用迭代器调试的代码混合使用。非常根本的不匹配,这些模板类对象的大小不同。如果您确实想这样做,那么您必须禁用从该功能获得的诊断信息。

这需要使用 #define 0 的 _HAS_ITERATOR_DEBUGGING 宏来构建代码的调试版本。您确定要这样做吗?

Library writers don't have great options to point out that mixing and matching does not work. They have to trigger linker errors, always tricky and confuzzling. What doesn't work here is that you cannot mix a library that uses the STL classes with iterator debugging enabled with code that has it disabled. Pretty fundamental mismatch, those template class objects are not the same size. If you really want to do this then you'll have to disable the diagnostics you get from the feature.

That requires building the debug version of your code with the _HAS_ITERATOR_DEBUGGING macro #defined to 0. Are you sure you want to do this?

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