Error lnk2038: detected “_ ITERATOR_ DEBUG_ Mismatched ‘level’ value of ‘0’

Problem description: the C++ program developed by Visual Studio 2010, after adding the h and CPP files of the third-party library, reported the following error when compiling and running:
Error LNK2038: “_ITERATOR_DEBUG_LEVEL” mismatches detected: value “0” mismatches value “2”Problem analysis: _ITERATOR_DEBUG_LEVEL is the system variable that records the compilation mode, 0 means that the current project is the Debug version, 2 means that the current project is the Release version.

Possible reasons 1:

Error 25 error LNK2038: Mismatch detected for "_ITERATOR_DEBUG_LEVEL": value "0" does not match value "2”

This problem is caused because the current project is the Debug version, but the library file referenced is the Release version.

“_ITERATOR_DEBUG_LEVEL” mismatch: value "2" does not match value "0"   

If the above problem is detected, then Release mode refers to Debug’s library file. This type of problem requires careful version matching when referring to files
Solution: Fix the lib file name in the attachment dependency. In Debug mode, you just use the file name of the Debug DLL, and in Release mode, you just use the Release DLL. (Debug mode DLL files usually have d, in, at the end of the file name)

Possible cause 2: Incorrect project property Settings, solution — “properties” — “C/C++–” Code generation — “runtime properties.
This property should be set to “multi-threaded debugging DLL (/MDd)” in Debug mode and” multi-threaded DLL (/MD) “in release mode. The above problem can also occur if the Settings are reversed.
Ending method: Just modify the runtime properties according to the schema.

Possible reason 3: If neither of the above reasons is true, the _ITERATOR_DEBUG_LEVEL variable may have been artificially assigned in the code.
For example, the basicexcel.cpp file contains the following statements:

#ifdef _DEBUG
#define _ITERATOR_DEBUG_LEVEL 0	// speedup iterator operations while debugging
#endif

The same problem may occur if _ITERATOR_DEBUG_LEVEL is set to 0 in Debug mode in order to speed up the program running in Debug mode, so that _ITERATOR_DEBUG_LEVEL values do not match in Debug mode.

Solution: Changing _ITERATOR_DEBUG_LEVEL to an appropriate value in the program can solve the problem.

Read More: