C++ 错误 LNK2038:检测到“_ITERATOR_DEBUG_LEVEL”不匹配:值“0”与 main.obj 中的值“2”不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7668200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
提问by Qbunia
I have read a lot of solutions to my problem but none helped. I tried clean, rebuild. Reinstalled visual 2010 and change from professional to ultimate. But still I dont know why I have this error. My project look like this: 1 Exe Solution to test my static library. 1 Dll Solution static library. Code which is converted to dll is using function from 1 lib called ClassificationFramework. I provided this lib as headers and cpp so basically source code. In Exe solution I linked my generated library + some other libs to run it + ClassificationFramework.dll. Everything works fine when I use Release but when I change to Debug (because I want to debug some stuff, I am tired of skipping debugger in release mode) I get this:
我已经阅读了很多解决我的问题的方法,但都没有帮助。我尝试清理,重建。重新安装了visual 2010,从专业版到终极版。但我仍然不知道为什么我有这个错误。我的项目如下所示: 1 Exe 解决方案来测试我的静态库。1 Dll 解决方案静态库。转换为 dll 的代码正在使用来自 1 个名为 ClassificationFramework 的库的函数。我提供了这个库作为头文件和 cpp,所以基本上是源代码。在 Exe 解决方案中,我链接了我生成的库 + 其他一些库来运行它 + ClassificationFramework.dll。当我使用 Release 时一切正常,但是当我更改为 Debug 时(因为我想调试一些东西,我厌倦了在发布模式下跳过调试器)我得到了这个:
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
When I build in Release I also got these warnings:
当我在 Release 中构建时,我也收到了这些警告:
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
I found that Debugger skips because of wrong path to pdb files.
我发现调试器因为 pdb 文件的路径错误而跳过。
'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).
When i go to Debug->Windows->Modules i see that he cannot find those pdb files or something. How i can say him that those files are here here and here? I tried to run MSvisual as administrator but that too didnt help. I used microsoft server to load pdb files but also didnt help.
当我转到 Debug->Windows->Modules 时,我看到他找不到那些 pdb 文件或其他东西。我怎么能告诉他这些文件在这里和这里?我尝试以管理员身份运行 MSvisual,但这也无济于事。我使用微软服务器加载 pdb 文件,但也没有帮助。
回答by AJG85
In VS2010 iterator debug level defaults to 2 in debug and is disabled in release. One of the dlls you are using probably has iterator debugging turned off in debug either because it was built in an older version of visual studio or they explicitly added the defines to the project.
在 VS2010 迭代器调试级别在调试中默认为 2,在发布中禁用。您正在使用的 dll 之一可能在调试中关闭了迭代器调试,因为它是在旧版本的 Visual Studio 中构建的,或者它们明确地将定义添加到项目中。
Search for _ITERATOR_DEBUG_LEVEL
and _SECURE_SCL
remove them or set them appropriately in all projects and sources and rebuild everything.
搜索_ITERATOR_DEBUG_LEVEL
并_SECURE_SCL
删除它们或在所有项目和源中适当地设置它们并重建所有内容。
_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)
In short you are probably mixing release and debug dlls. Don't linked release dlls in debug or vice versa!
简而言之,您可能正在混合发布和调试 dll。不要在调试中链接发布 dll,反之亦然!
回答by Francis Pierot
I make a little update on this issue, as I just had the same error today on an application which is linking against a static lib, after I migrated the old Visual 6 project to Visual Studio 2012.
我对这个问题进行了一些更新,因为在我将旧的 Visual 6 项目迁移到 Visual Studio 2012 之后,我今天在链接到静态库的应用程序上遇到了同样的错误。
In my case the error was that I mistakenly compiled the Release version of the static lib with /MDdinstead of /MD, whereas the application is /MDin release. Setting the correct /MD in the static lib project solved the issue.
在我的情况下,错误是我错误地使用/MDd而不是/MD编译了静态库的发布版本,而应用程序是/MD在发布中。在静态库项目中设置正确的 /MD 解决了这个问题。
This is done in Project properties
这是在项目属性中完成的
- Select Configuration Properties / C C++ / Code Generationin the tree
- and the option Runtime Libraryset to the same on all your dependencies projects and application.
- 在树中选择Configuration Properties / C C++ / Code Generation
- 并且选项Runtime Library在所有依赖项项目和应用程序上设置为相同。
回答by Antonio Maiorano
If you would like to purposely link your project A in Release against another project B in Debug, say to keep the overall performance benefits of your application while debugging, then you will likely hit this error. You can fix this by temporarily modifying the preprocessor flags of project B to disable iterator debugging (and make it match project A):
如果您想有意将 Release 中的项目 A 与 Debug 中的另一个项目 B 相关联,比如在调试时保持应用程序的整体性能优势,那么您可能会遇到此错误。您可以通过临时修改项目 B 的预处理器标志以禁用迭代器调试(并使其与项目 A 匹配)来解决此问题:
In Project B's "Debug" properties, Configuration Properties -> C/C++ -> Preprocessor, add the following to Preprocessor Definitions:
在项目 B 的“调试”属性中,配置属性 -> C/C++ -> 预处理器,将以下内容添加到预处理器定义中:
_HAS_ITERATOR_DEBUGGING=0;_ITERATOR_DEBUG_LEVEL=0;
_HAS_ITERATOR_DEBUGGING=0;_ITERATOR_DEBUG_LEVEL=0;
Rebuild project B in Debug, then build project A in Release and it should link correctly.
在 Debug 中重建项目 B,然后在 Release 中构建项目 A,它应该正确链接。
回答by stoney
I had a mismatch between projects: one with multi-byte character set, the other with Unicode. Correcting these to agree on Unicode corrected the problem.
我在项目之间不匹配:一个使用多字节字符集,另一个使用 Unicode。更正这些以就 Unicode 达成一致更正了问题。
回答by Aviad Rozenhek
The error can be caused by mixing together debug builds and release builds in same executable or dll.
该错误可能是由在同一可执行文件或 dll 中混合调试版本和发布版本引起的。
- in the vs configuration manager, are some of your projects in debug mode and some in release mode?
- is one of your release projects has the preprocessor symbol DEBUG or _DEBUG defined?
- is one of your debug projects has the preprocessor symbol NDEBUG defined?
- 在 vs 配置管理器中,你的一些项目是在调试模式还是在发布模式?
- 您的发布项目之一是否定义了预处理器符号 DEBUG 或 _DEBUG?
- 您的调试项目之一是否定义了预处理器符号 NDEBUG?
回答by ArtHare
I had this problem as well.
我也有这个问题。
My problem was that I had copy/pasted the library include directories from my debug configurations.
我的问题是我从调试配置中复制/粘贴了库包含目录。
So project "Indep" was including static library "Dep.lib" from "../Debug", even in release. The fix was to change the library directory to "../Release" so I caught the release-built library rather than the previously-built debug library.
所以项目“Indep”包括来自“../Debug”的静态库“Dep.lib”,即使在发布中也是如此。修复是将库目录更改为“../Release”,因此我捕获了发布构建的库而不是先前构建的调试库。
回答by AlexT
Try change _DEBUG to NDEBUG macro definition in C++ project properties (for Release configuration) Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions
尝试将 C++ 项目属性中的 _DEBUG 宏定义更改为 NDEBUG 宏定义(用于发布配置) Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions
回答by Alstrice
I had the same issue between debug and release libraries. The mistake was in the solution properties / Configurations properties / Configurations.
我在调试库和发布库之间遇到了同样的问题。错误出在解决方案属性/配置属性/配置中。
The projects configurations did not match the main configuration / platform.
项目配置与主要配置/平台不匹配。
回答by Ionut V.
In my case, for both Debug and Release, the solution was to clean then rebuild entire solution.
就我而言,对于 Debug 和 Release,解决方案是清理然后重建整个解决方案。
Edit: true in my case also (VS2017) step1: clean the project. step2: change configuration mode(from debug to release or vice versa). step3: clean the project. step4: build in the required configuration mode.
编辑:在我的情况下也是如此(VS2017) step1:清理项目。step2:更改配置模式(从调试到发布,反之亦然)。step3:清理项目。step4:在需要的配置模式下构建。
PS: to change config mode, find config settings under build menu
PS:要更改配置模式,请在构建菜单下找到配置设置
回答by Andrey
Last chance (if other ways don't work): define _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH macro in all projects. It will disable "#pragma detect_mismatch" feature which is used in CRT headers.
最后的机会(如果其他方法不起作用):在所有项目中定义 _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH 宏。它将禁用 CRT 标头中使用的“#pragma detect_mismatch”功能。