43

I've just moved over a Visual Studio (C++) solution over to another computer, setup all the directories and settings as far as I can see, and did a clean/rebuild on the solution. I get the error above on a bunch of .obj's on compile, not sure what to do about it.

Contango
  • 76,540
  • 58
  • 260
  • 305
meds
  • 21,699
  • 37
  • 163
  • 314

8 Answers8

34

It seems that you are mixing object files built with different settings. Try to do a full clean rebuild and check all project file settings to make sure that the _ITERATOR_DEBUG_LEVEL macro is the same (e.g., you are not mixing debug and release built objects).

Michael Goldshteyn
  • 71,784
  • 24
  • 131
  • 181
  • 6
    For some reason one of my projects had _SECURE_SCL=1 defined in release mode and this caused the linker error. – Gyuri Mar 10 '12 at 05:29
  • Another possibility is some project/source file defining _HAS_ITERATOR_DEBUGGING – korbes Dec 02 '16 at 18:54
22

In some cases, mixing the options in

Properties>Configuration Properties>C/C++>Code Generation>Runtime Library

Between included Library(ies) and currently working project can cause this problem.

Depending on usage set it as /MD or /MT or /MDd or /MTd uniformly across all projects.

21

Mixing binaries (object files) is one reason; another (which I encountered) is the false definition of the _DEBUG macro in the release build. _DEBUG is not a standard macro, but used by Microsoft.

After editing the .vcxproj-file in Emacs I mistyped _DEBUG instead of NDEBUG for the release, and encountered precisely the same build error.

Andreas Spindler
  • 7,568
  • 4
  • 43
  • 34
  • Also be aware: "#define _DEBUG 0" will compile using the *debug* CRT regardless the project settings. _DEBUG must be *undefined* to compile using the release CRT. – TeasingDart Mar 19 '23 at 16:47
2

I have been trying to solve this issue for five days. The Point Cloud Library (PCL) code builds successfully in debug mode but fails in release mode.

I have reconfigured my library several times but it didn't help. I found the problem was that the release version was inheriting _DEBUG so I unchecked it under project properties >> Preprocessor >> Processor Definitions and it was solved.

John Duke
  • 67
  • 1
  • 9
1

I found out (oddly) that _CRT_NON_CONFORMING_SWPRINTFS causes it. When I remove it, I don't get "_iterator_debug_level value '0' doesn't match value '2'" but instead the following warning:

Error 6 error C4996: '_swprintf': swprintf has been changed to conform with the ISO C standard, adding an extra character count parameter. To use traditional Microsoft swprintf, set _CRT_NON_CONFORMING_SWPRINTFS.

Michael Haephrati
  • 3,660
  • 1
  • 33
  • 56
1

After trying to solve issue for several days in a debug version of my VS2019 project. Setting the Project >> Properties >> C/C++ >> Processor _HAS_ITERATOR_DEBUGGING=0 definition worked for me.

alman
  • 83
  • 6
0

In my particular case, I encountered this error when using Conan with CMake while following their tutorial. When I generated the Visual Studio project, it built fine in Release mode but threw this error in Debug mode.

The solution was to generate a separate Visual Studio project with Debug libraries:

mkdir debug && cd debug
conan install --build=missing .. -s build_type=Debug
cmake ..

Can repeat the same in Release mode: change directory in line #1 and in line #2 use any one of ['None', 'Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel']

Contango
  • 76,540
  • 58
  • 260
  • 305
-1

For each project in the solution, edit the preprocessor definitions by choosing the <Edit...> dropdown found under project properties: C/C++ > Preprocessor > Preprocessor Definitions. Check to make sure the evaluated values do not include _DEBUG. For release mode, replace any _DEBUG with NDEBUG, meaning NO DEBUG. You must do this for every project in the solution. Even one project will force Microsoft to use debug libraries and will generate the error you are encountering.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 31 '23 at 03:34