174

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:

    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:

    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.

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

Tim Post
  • 33,371
  • 15
  • 110
  • 174
Qbunia
  • 1,813
  • 2
  • 13
  • 14

23 Answers23

179

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.

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 = 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!

AJG85
  • 15,849
  • 13
  • 42
  • 50
  • 7
    I dont see in any .h or .cpp file any of _ITERATOR_DEBUG_LEVEL or _SECURE_SCL They exist only in obj files as: /FAILIFMISMATCH:"_ITERATOR_DEBUG_LEVEL=0" What about – Qbunia Oct 06 '11 at 08:18
  • What about skipping breakpoints by debugger in release? Some breakpoints are not filled and says debugger avoid them because of optimalization or linking something like this – Qbunia Oct 06 '11 at 08:26
  • 1
    debugging in release is always sketchy because release builds usually don't have debug symbols. You may have incorrect stacks and missed breakpoints. Due to optimization the code may not be the same as what you are looking at. `_ITERATOR_DEBUG_LEVEL` would probably be defined in the vcproj files if not then make sure you use debug dlls with debug exe and release dlls with release exe. – AJG85 Oct 06 '11 at 15:37
  • 55
    "In short you are probably mixing release and debug dlls" helped me. Thanks! – max Apr 26 '13 at 06:12
  • +1 I was using release libs in a debug build as well, thanks ! – Laurent Couvidou Jun 13 '13 at 13:38
  • 11
    Waiwaiwait ! You mean to tell me that when I'm using MSVC, to get a Debug build I must recompile ALL the dependencies ? Even those I don't care to debug ? What the shit man ! I can't believe this ! – Michael Jul 10 '13 at 05:48
  • @user626921 You have to compile all YOUR dependencies, since CRT libs are maintained by Microsoft if you're using Visual Studio then you simply link to the existing redistributable that got installed on your machine same as any other 3rd party library. The only tricky business is ensuring all your projects are linking to the right CRT libs for the target build you want as mismatches between release and debug libraries or other options can cause problems. – AJG85 Sep 11 '13 at 21:00
  • Why not allow release libs in debug mode with the corresponding graceful degradation in functionality (i.e. the code in the libs can't be properly debugged)? The more I look at C++, the more I like Java and C#. I mean, surely we could get the performance of C++ without having to work full time to manage administrative details if only the tool designers cared. – Mihai Danila Nov 29 '13 at 21:35
  • @MihaiDanila Just the opposite actually the performance of C++ is largely due to native compiled optimizations allowed by the standard which does not leave room for debugging info and wasteful overhead. Yes, you are required to know what you are doing but that is not a bad thing. Languages like C# that use managed intermediate layers or worse languages like Java that do that in addition to running within a virtual abstraction of the OS are always going to be slower because of this. That said use the right tool for the job at hand. I personally use all 3 of those languages regularly ;-) – AJG85 Mar 07 '14 at 16:43
  • Perhaps these conundrums go away as one becomes more acquainted to the language and its idiosyncrasies. But on the surface it seems overkill to enforce exact matching of debug levels across the components of a project in the name of performance, since we know full well that reduced performance is generally accepted and expected by the developer while the software is being developed on. Even so, can the error be more descriptive at least? Capture some common sense error level quality expectations in the standard or something. :) – Mihai Danila Mar 12 '14 at 17:50
  • The _ITERATOR_DEBUG_LEVE‌​L is probably set in the "Projects Property Page->Configuration Propertys->C/C++ ->Preprocessor->Preprocessor Definitions" of the Debug Configuration – thewhiteambit Aug 15 '16 at 16:38
  • For me MSBuild made a bad assumption when I hadn't been explicit in my solution about related libraries. Searching the build log "Project reference .* has not been resolved" showed me the libraries I should have added. – erict Mar 09 '17 at 18:59
  • 1
    "In short you are probably mixing release and debug dlls" -> In my case the RuntimeLibrary was MultiThreadedDebugDLL in the Release build when it should have been MultiThreadedDLL. – Captain Normal Oct 30 '18 at 09:06
124

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.

In my case the error was that I mistakenly compiled the Release version of the static lib with /MDd instead of /MD, whereas the application is /MD in release. Setting the correct /MD in the static lib project solved the issue.

This is done in Project properties

  • Select Configuration Properties / C C++ / Code Generation in the tree
  • and the option Runtime Library set to the same on all your dependencies projects and application.
Stephan
  • 41,764
  • 65
  • 238
  • 329
Francis Pierot
  • 1,369
  • 1
  • 8
  • 9
  • 1
    This one solved for me. THumbs up for you. – IssamTP Nov 13 '21 at 14:12
  • 1
    It's good to see that solutions on Microsoft C++ compiler from 1998 reissued in 2012 are still up to date in 2021 :-) The debug vs release build issues are still something to know deep by 2021. – Francis Pierot Nov 14 '21 at 17:49
  • TBH I'm compiling Assimp Codec and some other stuff for Ogre, I guess some of them can be quite obsolete. – IssamTP Nov 15 '21 at 07:21
40

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

In Project B's "Debug" properties, Configuration Properties -> C/C++ -> Preprocessor, add the following to Preprocessor Definitions:

_HAS_ITERATOR_DEBUGGING=0;_ITERATOR_DEBUG_LEVEL=0;

Rebuild project B in Debug, then build project A in Release and it should link correctly.

Christian
  • 4,902
  • 4
  • 24
  • 42
  • 1
    In my case I wanted to keep both in debug mode. One of them was a new static library. I defined _ITERATOR_DEBUG_LEVEL=2 in the new library and it stopped the link error in the module that was linking to the new library. – qqqqq Feb 16 '23 at 06:27
12

The error can be caused by mixing together debug builds and release builds in same executable or dll.

  1. in the vs configuration manager, are some of your projects in debug mode and some in release mode?
  2. is one of your release projects has the preprocessor symbol DEBUG or _DEBUG defined?
  3. is one of your debug projects has the preprocessor symbol NDEBUG defined?
Aviad Rozenhek
  • 2,259
  • 3
  • 21
  • 42
11

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.

stoney
  • 111
  • 1
  • 2
  • 2
    It turns out that the project I was trying to build had this issue as well as an unexpected missing preprocessor in debug: _DEBUG. See http://forums.codeguru.com/showthread.php?519376-mismatch-detected-for-_ITERATOR_DEBUG_LEVEL-value-0-doesn-t-match-value-2&p=2050461#post2050461 – JGeerWM Nov 18 '14 at 17:03
  • I had a similar problem mexing in Matlab, but the other way round: I needed to change the VS2013 build to multi-byte to get the agreement. This also resolved a mismatch for RuntimeLIbrary. – barnhillec Aug 24 '15 at 19:56
11

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.

Andrey
  • 927
  • 11
  • 12
  • 2
    I tried pretty much everything on this page, and this was the only thing that worked. Add `_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH` under `C/C++ >> Preprocessor >> PreprocessorDefinitions`. – Contango Apr 16 '16 at 13:51
7

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.

ArtHare
  • 1,798
  • 20
  • 22
  • Had a similar problem, where my static lib landed in the same place regardless whether release or debug. In that case one should name them differently by appending 'd' or such. Otherwise you would also be forced to rebuild the lib everytime you switch between debug/release. – yau Sep 25 '16 at 17:00
6

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.

Alstrice
  • 79
  • 1
  • 4
5

Try change _DEBUG to NDEBUG macro definition in C++ project properties (for Release configuration) Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions

AlexT
  • 1,413
  • 11
  • 11
2

opencv_core245.lib(dxt.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in test.obj I got error like this.
I have opencv_core245.lib and opencv_core245d.lib in Linker->Input->Additional dependenc. Since this two were confilicting I removed first one opencv_core245.lib. Error gone.

Vinit M
  • 21
  • 1
2

Try this: Goto project property -> C/C++ -> Code generation -> Runtime Library Select from combobox value : Multi-threaded DLL (/MD) It work for me :)

Phạm Mạnh
  • 155
  • 1
  • 2
2

In my case, for both Debug and Release, the solution was to clean then rebuild entire solution.

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.

PS: to change config mode, find config settings under build menu

Community
  • 1
  • 1
Ionut V.
  • 110
  • 7
2

Small addition to the help above: I got the mismatch error after adding a static libto an older VST solution using VST 2017 . VST now generates "stdfax.h" for precompiled headers containing these 2 lines:

// Turn off iterator debugging as it makes the compiler very slow on large methods in debug builds
#define _HAS_ITERATOR_DEBUGGING 0
Ivan_a_bit_Ukrainivan
  • 808
  • 1
  • 10
  • 27
1

I had the same problem today (VS2010), I built Release | Win32, then tried to build Debug | Win32, and got this message.

I tried cleaning Debug | Win32 but the error still persisted. I then cleaned Release | Win32, then cleaned Debug | Win32, and then it built fine.

GilesDMiddleton
  • 2,279
  • 22
  • 31
1

I managed to get rid of this error (in my case using Ogre3D + Bullet) by changing the dependency libraries to the debug versions in Project Properties -> Linker -> Input -> Additional Dependencies (VC10).

I changed BulletCollision.lib to BulletCollision_debug.lib (for debug configuration) and it compiled.

JTatie
  • 93
  • 2
  • 5
1

I resolved my trouble in correcting the "Additional Library Directory", this one was wrong in indicating "$(SolutionDir)\Release", I changed it in "$(SolutionDir)\$(IntDir)"

To correct it, open your project properties -> Configuration Properties -> Linker -> General -> Additional Library Directory

I hope this will help some poeples with the same trouble ;)

ThierryV
  • 11
  • 1
  • so for me Debug works fine but when building in release I get the above error.... I opened Additional Library Directory I found: C:/Program Files/PCL 1.8.1/lib/$(Configuration) what should I add now here? – sqp_125 May 02 '19 at 06:59
0

I also had this issue and it arose because I re-made the project and then forgot to re-link it by reference in a dependent project.

Thus it was linking by reference to the old project instead of the new one.

It is important to know that there is a bug in re-adding a previously linked project by reference. You've got to manually delete the reference in the vcxproj and only then can you re-add it. This is a known issue in Visual studio according to msdn.

AtomicBoolean
  • 1,070
  • 13
  • 19
0

I had similar problem, but the wrong setting was in the extern .lib file from which I did not have sources. If you do not have the source files, the simplest workaround is to just change the content of the .lib file.

Open the .lib file in an editor (I used PSPad, bud Windows notepad is also possible) and replace all occurences of _ITERATOR_DEBUG_LEVEL=2 to _ITERATOR_DEBUG_LEVEL=0

napets
  • 133
  • 1
  • 7
0

In my case the NDEBUG macro definition in the "Preprocessor Definitions" needed to be changed to _DEBUG. I am building a static library for use in a .exe which was complaining about the very same error listed in the question. Go to Configuration Properties ("Project" menu, "Properties" menu item) and then click the C/C++, section, then the Preprocessor section under that, and then edit your Preprocessor Definitions so that NDEBUG is changed to _DEBUG (to match the setting in the exe).

Alyoshak
  • 2,696
  • 10
  • 43
  • 70
0

Like all the other answers, I checked my Configuration Properties -> C/C++ -> Preprocessor directives.
In my case I had the NDEBUG correctly defined in Release, but I also had: _SECURE_SCL=1.

Removing that one fixed the issue.

Coxy
  • 8,844
  • 4
  • 39
  • 62
0

For me it's just a properties problem, change C/C++ /code generation/MDd to MD solved it

0

Ditto. I was linking a Release-level library to a Debug EXE.

Cause of problem: I had included the .LIB by right-clicking on the Project in Solution Explorer, choosing "Add ➔ Existing Item" and browsing to the .LIB file.

Fix: Go to Project Properties instead. Include a different .LIB in each of the Debug and Release by adding them to the list. Go to Linker ➔ Input, and add the version of the .LIB appropriate for the Configuration.

Pierre
  • 4,114
  • 2
  • 34
  • 39
0

one of the projects is set to debug and others are set to release in configuration manager.. was lost in all other settings.

Kvae Kvae22
  • 111
  • 1
  • 5