错误LNK2038:为'_ITERATOR_DEBUG_LEVEL'检测到不匹配:值'0'与main.obj中的值'2'不匹配

我已经阅读了很多解决我的问题,但没有帮助。 我试图干净,重build。 重新安装visual 2010并从专业改为终极。 但是我仍然不知道为什么我有这个错误。 我的项目是这样的:1 Exe解决scheme来testing我的静态库。 1个DLL解决scheme静态库。 被转换为dll的代码是使用来自1个名为ClassificationFramework的库的函数。 我提供这个库作为标题和CPP,所以基本上是源代码。 在Exe解决scheme中,我链接了我生成的库+一些其他库以运行它+ ClassificationFramework.dll。 一切工作正常,当我使用释放,但当我更改为debugging(因为我想debugging一些东西,我厌倦了在发布模式中跳过debugging器)我得到这个:

2>Link: 2> ClassificationFramework.lib(SampleClass.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance 2>ClassificationFramework.lib(SampleClass.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj 2>ClassificationFramework.lib(SampleNamesSet.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj 2>ClassificationFramework.lib(SampleSet.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj 2>ClassificationFramework.lib(DirectoryReader.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj 2>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library 2>C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\Transformer\Debug\Tester.exe : fatal error LNK1319: 4 mismatches detected 

当我build立释放我也得到这些警告:

  1>Link: 1> Generating code 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(101): warning C4748: /GS can not protect parameters and local variables from local buffer overrun because ptimizations are disabled in function 1>c:\users\kasia\documents\visual studio 2010\projects\classificationframework\classificationframework\directoryreader.cpp(30): warning C4748: /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xstring(1589): warning C4748: /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function 1>c:\users\kasia\documents\visual studio 2010\projects\classificationframework\classificationframework\samplenamesset.cpp(226): warning C4748: /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function 1>c:\users\kasia\documents\visual studio 2010\projects\classificationframework\classificationframework\directoryreader.cpp(60): warning C4748: /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function 1>c:\users\kasia\documents\visual studio 2010\projects\classificationframework\classificationframework\samplenamesset.cpp(199): warning C4748: /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function 1>c:\users\kasia\documents\visual studio 2010\projects\classificationframework\classificationframework\sampleset.cpp(27): warning C4748: /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function 1>c:\users\kasia\documents\visual studio 2010\projects\classificationframework\classificationframework\samplenamesset.cpp(59): warning C4748: /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function 1> Finished generating code 1>ClassificationFramework.lib(SampleSet.obj) : warning LNK4099: PDB 'vc100.pdb' was not found with 'ClassificationFramework.lib(SampleSet.obj)' or at 'C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\Transformer\Release\vc100.pdb'; linking object as if no debug info 1>ClassificationFramework.lib(SampleNamesSet.obj) : warning LNK4099: PDB 'vc100.pdb' was not found with 'ClassificationFramework.lib(SampleNamesSet.obj)' or at 'C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\Transformer\Release\vc100.pdb'; linking object as if no debug info 1>ClassificationFramework.lib(SampleClass.obj) : warning LNK4099: PDB 'vc100.pdb' was not found with 'ClassificationFramework.lib(SampleClass.obj)' or at 'C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\Transformer\Release\vc100.pdb'; linking object as if no debug info 1>ClassificationFramework.lib(DirectoryReader.obj) : warning LNK4099: PDB 'vc100.pdb' was not found with 'ClassificationFramework.lib(DirectoryReader.obj)' or at 'C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\Transformer\Release\vc100.pdb'; linking object as if no debug info 1> Tester.vcxproj -> C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\Transformer\Release\Tester.exe 

我发现debugging程序因为pdb文件的path错误而跳过。

 'Tester.exe': Loaded 'C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\Work\Release\Tester.exe', Symbols loaded. 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\kernel32.dll', Cannot find or open the PDB file 'Tester.exe': Unloaded 'C:\WINDOWS\SysWOW64\kernel32.dll' 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\ntdll.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\kernel32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\OpenCV2.2\bin\opencv_core220.dll', Binary was not built with debug information. 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\msvcp100.dll', Symbols loaded. 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\msvcr100.dll', Symbols loaded. 'Tester.exe': Loaded 'C:\OpenCV2.2\bin\opencv_highgui220.dll', Binary was not built with debug information. 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\user32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\gdi32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\advapi32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\secur32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\ole32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\msvcrt.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_5.82.3790.4770_x-ww_A689AB02\comctl32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\avifil32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\winmm.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\msacm32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\msvfw32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\shell32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\shlwapi.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\avicap32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\version.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\OpenCV2.2\bin\opencv_imgproc220.dll', Binary was not built with debug information. 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\imm32.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\lpk.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\SysWOW64\usp10.dll', Cannot find or open the PDB file 'Tester.exe': Loaded 'C:\WINDOWS\WinSxS\wow64_Microsoft.Windows.Common- Controls_6595b64144ccf1df_6.0.3790.4770_x-ww_8D2E3180\comctl32.dll', Cannot find or open the PDB file The program '[4984] Tester.exe: Native' has exited with code 0 (0x0). 

当我去debugging – > Windows->模块,我看到他无法find这些PDB文件或东西。 我怎么能说他这些文件在这里和这里? 我试图以pipe理员身份运行MSvisual,但也没有帮助。 我用微软服务器来加载pdb文件,但也没有帮助。

在VS2010中,迭代器的debugging级别在debugging中默认为2,在发布时禁用。 您正在使用的dll中的一个可能在debugging中closures了迭代器debugging,因为它是在Visual Studio的较早版本中构build的,或者他们明确将定义添加到项目中。

search_ITERATOR_DEBUG_LEVEL_SECURE_SCL删除它们或在所有项目和来源中适当地设置它们并重build所有内容。

 _ITERATOR_DEBUG_LEVEL = 0 // disabled (for release builds) _ITERATOR_DEBUG_LEVEL = 1 // enabled (if _SECURE_SCL is defined) _ITERATOR_DEBUG_LEVEL = 2 // enabled (for debug builds) 

总之你可能混合了发行版和debuggingDLL。 不要在debugging中连接发布DLL,反之亦然!

我在这个问题上做了一些更新,因为在我将旧的Visual 6项目迁移到Visual Studio 2012之后,我今天在一个与静态库链接的应用程序上出现了相同的错误。

在我的情况下,错误是我错误地编译静态库的发布版本与/ MDD而不是/ MD ,而应用程序是/ MD在发布。 在静态lib项目中设置正确的/ MD解决了这个问题。

这在项目属性中完成

  • 在树中selectconfiguration属性/ C C ++ /代码生成
  • 和选项运行时库设置为相同的所有依赖项目和应用程序。

如果您想故意将您的项目A与Release中的另一个项目B相关联,比如在debugging时保持应用程序的整体性能优势,那么您可能会遇到此错误。 您可以通过临时修改项目B的预处理器标志来禁用迭代器debugging(并使其与项目A匹配)来解决此问题:

在项目B的“debugging”属性,configuration属性 – > C / C ++ – >预处理器中,将以下内容添加到预处理器定义中:

_HAS_ITERATOR_DEBUGGING = 0; _ITERATOR_DEBUG_LEVEL = 0;

在Debug中重build项目B,然后在Release中构build项目A,并正确链接。

该错误可能是由debugging版本和释放版本混合在一起的可执行文件或DLL造成的。

  1. 在vsconfigurationpipe理器中,有些项目处于debugging模式,还有一些处于发布模式?
  2. 是您的发布项目之一有预处理器符号DEBUG或_DEBUG定义?
  3. 是您的debugging项目之一是否有预处理器符号NDEBUG定义?

我之间的项目不匹配:一个与多字节字符集,另一个与Unicode。 更正这些以达成Unicode修正了这个问题。

我也有这个问题。

我的问题是,我从我的debuggingconfiguration复制/粘贴库包含目录。

因此,“Indep”项目包含了“../Debug”中的静态库“Dep.lib”,即使在发行版中也是如此。 解决的办法是把库目录改成“../Release”,所以我抓到了发布版本库,而不是之前build立的debugging库。

尝试在C ++项目属性(用于发布configuration)中更改_DEBUG到NDEBUGmacros定义configuration属性 – > C / C ++ – >预处理器 – >预处理器定义

试试这个:Goto项目属性 – > C / C ++ – >代码生成 – >运行时库从combobox值select:multithreadingDLL(/ MD)它为我工作:)

最后的机会(如果其他方式不起作用):在所有项目中定义_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCHmacros。 它将禁用在CRT标题中使用的“#pragma detect_mismatch”function。

在我的情况下,对于debugging和发布,解决scheme是清理,然后重build整个解决scheme。

今天我有同样的问题(VS2010),我build立了Release | Win32,然后试图构buildDebug | Win32,并得到这个消息。

我试图清洗debugging| Win32,但错误仍然存​​在。 然后我清理释放| Win32,然后清除Debug | Win32,然后它build立好。

opencv_core245.lib(dxt.obj):错误LNK2038:为'_ITERATOR_DEBUG_LEVEL'检测到不匹配:值'0'与test.obj中的值'2'不匹配我得到这样的错误。
在链接器 – >input – >附加依赖关系中,我有opencv_core245.lib和opencv_core245d.lib。 由于这两个是confilicting我删除了第一个opencv_core245.lib。 错误消失了

我设法摆脱这个错误(在我的情况下使用Ogre3D +项目符号),通过更改项目属性 – >连接器 – >input – >附加依赖项(VC10)中的依赖库的debugging版本。

我将BulletCollision.lib更改为BulletCollision_debug.lib(用于debuggingconfiguration)并编译。

我也有这个问题,因为我重新做了这个项目,然后忘了把它通过一个依赖项目的引用重新链接起来。

因此,它是通过引用旧项目而不是新项目。

重要的是要知道,通过引用重新添加以前链接的项目存在一个错误。 您必须手动删除vcxproj中的引用,然后才能重新添加引用。 根据msdn,这是Visual Studio中的一个已知问题。

我有类似的问题,但错误的设置是在我没有源的extern .lib文件中。 如果您没有源文件 ,最简单的解决方法是只更改.lib文件的内容。

在编辑器中打开.lib文件(我使用了PSPad,bud Windows的记事本也是可能的),并将_ITERATOR_DEBUG_LEVEL = 2的所有出现replace为_ITERATOR_DEBUG_LEVEL = 0

在我的情况下,“预处理器定义”中的NDEBUGmacros定义需要更改为_DEBUG。 我build立一个静态库,用于一个.exe,它抱怨在问题中列出了非常相同的错误。 转到configuration属性(“项目”菜单,“属性”菜单项),然后单击C / C ++部分,然后单击预处理器部分,然后编辑预处理器定义,以便NDEBUG更改为_DEBUG(以匹配设置在EXE)。

像所有其他答案一样,我检查了我的Configuration Properties -> C/C++ -> Preprocessor指令。
在我的情况下,我已经在Release中正确定义了NDEBUG ,但是我也有: _SECURE_SCL=1

删除那一个解决了这个问题。