LNK2038,迭代器不匹配错误,需要忽略
尝试将 VS2008 项目转换为 VS2010 时,出现链接器错误 LNK2038。当编译两个不同的项目,其中一个使用 _DEBUG 预处理器宏,而另一个不使用时,会出现此错误。基本上我有一个只有发行版 .libs 的第 3 方库,因此当我在调试模式下构建项目时尝试使用该库时,我会遇到这种不匹配的情况。
我理解为什么微软会给出这个错误(STL迭代器安全),但是我们的项目不使用微软的STL,我们使用STLPort,所以这个错误对我们的项目没有任何意义。我只需要一种方法来阻止它进行此检查。
STL 内部包含一个名为 yvals.h 的文件,其中包含各种 _ITERATOR_DEBUG_LEVEL 设置的#pragma detector_mismatch 定义。该组定义包含在 #ifndef _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH、#endif 中。但是,即使我将 _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH 定义为整个项目的预处理器宏,我仍然会遇到相同的链接器错误。我什至可以更改 yvals.h 来定义该宏,但它什么也不做(我假设是因为 STL 本身需要重新编译)。
所以我的问题基本上是,我可以采取哪些步骤使 _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH 实际上按预期工作,以便我的项目在 VS2010 中编译时不会在任何地方进行此检查?
编辑:我知道这是一个迟到的回复,但我刚刚找到这篇文章并意识到我没有发布解决方案。正如其他人提到的,库中存在不匹配的情况。事实证明 VS2010 更改了某些项目的默认目录(我在 MSDN 上发现了一个帖子,其中充满了对此的抱怨),并且该目录更改导致 VS2010 在错误的目录中查找调试库,并且它是而是找到发布库。
I'm getting the linker error LNK2038 when trying to convert a VS2008 project to VS2010. This error occurs when two different projects are compiled in which one is using _DEBUG preprocessor macro, and the other is not. Basically I have a 3rd party library that only has release .libs, so when I try and use that library when building my project in debug mode I get this mismatch.
I understand why Microsoft is giving this error (STL iterator safety), however our project does not use Microsoft's STL, we use STLPort, so this error means nothing to our project. I just need a way to prevent it from doing this check.
Inside of the STL includes there is a file called yvals.h, which includes the #pragma detect_mismatch definition for the various _ITERATOR_DEBUG_LEVEL settings. That set of definitions is wrapped in an #ifndef _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH, #endif. However, even if I define _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH as a preprocessor macro for my entire project I'm still getting the same linker error. I can even alter yvals.h to define that macro and it does nothing (I'm assuming because the STL itself would need to be recompiled).
So my question is basically, what steps can I take make _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH actually work as intended so that my project doesn't do this check anywhere when compiling in VS2010?
EDIT: I know this is a late response but I just found this post and realized I didn't post the solution. As others mentioned there was a mismatch in the libraries. As it turns out VS2010 changes the default directories for certain projects (I found a thread on MSDN at one point full of complaints about it), and that directory change had caused VS2010 to look in the wrong directory for the debug library, and it was finding the release library instead.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用相同版本的标准库,并使用
如果您希望成功链接,则可以使用相同的选项。如果您使用 STLPort,
那么你只能链接到使用 STLPort 的库,而不能链接到
使用 VC++ 标准实现的库。如果你混合,
要么链接失败,要么出现奇怪的运行时错误。
问题是像
std::vector<>::iterator
这样的东西可能被定义完全不同;根据它们的使用地点和方式,您
会发现自己使用的是在不同库中构建的实例,
具有不同的布局。
You must use the same version of the standard library, compiled with the
same options, if you expect to successfully link. If you use STLPort,
then you can only link with libraries which use the STLPort, not with
libraries which use the VC++ standard implementation. If you mix,
either you will fail to link, or you will get strange runtime errors.
The problem is that things like
std::vector<>::iterator
may be definedcompletely differently; depending on where and how they are used, you
will find yourself using an instance constructed in a different library,
with a different layout.