LNK2038,迭代器不匹配错误,需要忽略 [英] LNK2038, iterator mismatch error, need to ignore

查看:360
本文介绍了LNK2038,迭代器不匹配错误,需要忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将VS2008项目转换为VS2010时,我收到链接器错误LNK2038。编译两个不同的项目时会发生此错误,其中一个使用_DEBUG预处理器宏,另一个不使用.DEBUG预处理器宏。基本上我有一个第三方库,只有发布.libs,所以当我在调试模式下构建我的项目时尝试使用该库时,我得到了这个不匹配。

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理解为什么微软会给出这个错误(STL迭代器安全),但是我们的项目不使用微软的STL,我们使用STLPort,所以这个错误对我们的项目没有任何意义。我只需要一种方法来防止它进行此检查。

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.

在STL内部包含一个名为yvals.h的文件,其中包含#pragma detect_mismatch定义各种_ITERATOR_DEBUG_LEVEL设置。这组定义包含在#ifndef _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH,#endif中。但是,即使我将_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH定义为整个项目的预处理器宏,我仍然会遇到相同的链接器错误。我甚至可以改变yvals.h来定义那个宏而它什么都不做(我假设因为STL本身需要重新编译)。

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).

所以我的问题是基本上,我可以采取哪些步骤_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH实际上按预期工作,以便我的项目在VS2010中编译时不进行任何检查?

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?

编辑:我知道这是迟到的回应,但我刚发现这篇文章,并意识到我没有发布解决方案。正如其他人提到的那样,图书馆存在不匹配。事实证明,VS2010更改了某些项目的默认目录(我在MSDN上发现一个线程,其中充满了关于它的投诉),并且该目录更改导致VS2010查找调试库的错误目录,并且它是改为找到发布库。

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.

推荐答案

你必须使用相同版本的标准库,用
编译相同选项,如果您希望成功链接。如果你使用STLPort,
那么你只能链接到使用STLPort的库,而不是使用VC ++标准实现的
库。如果你混合,
你将无法链接,或者你会得到奇怪的运行时错误。

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.

问题是像这样的事情std :: vector<> :: iterator 可以完全不同地定义
;取决于它们在何处以及如何使用,你
会发现自己使用在不同库中构建的实例,
具有不同的布局。

The problem is that things like std::vector<>::iterator may be defined completely 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.

这篇关于LNK2038,迭代器不匹配错误,需要忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆