24

I'm trying to use the /O2 optimization for my project. I checked that the release configuration was enabled (Solution->Properties->Configuration Properties->Configuration->Release) and set Debug Information Format to /Zi but now I don't know what to do for this error.

justHelloWorld
  • 6,478
  • 8
  • 58
  • 138
  • What version of Visual Studio are you using? – TriskalJM May 03 '16 at 15:17
  • Starting at Solution->Properties is not helpful. It appears you have changed the /O2 setting for the Debug configuration, it uses /RTC. Switch to the Release configuration instead, it already uses /O2 and /Zi so no help is needed. Use Build > Configuration Manager > Active solution configuration to switch. And restore the setting. – Hans Passant May 03 '16 at 16:21
  • If you'll post it as an answer I'll chose it :) – justHelloWorld May 04 '16 at 08:05
  • 1
    It's not quite related to the question, but I didn't find the answer in time for myself. It you are using the cmake with Visual Studio generator, then the cmake from some version adds `/O2` flag implicitly to the generated Debug project if didn't found it in the `CMAKE_CXX_FLAGS_DEBUG` variable. Basically this variable has used with the `/RTC1` flag already set, so you have to explicitly add the `/Od` flag to it to avoid that behaviour. In my case I did explicitly remove the `/Od` flag from the variable and got the issue. – Andry May 13 '20 at 07:45

1 Answers1

37

The optimization setting Maximize Speed (/O2) is incompatible to the Basic Runtime Checks setting of Code Generation.

To change the settings for Basic Runtime Checks:

Solution -> Properties -> Configuration Properties -> C/C++ -> Code Generation -> Basic Runtime Checks

Set it to "Default", and it should work.

enter image description here

mohaghighat
  • 1,293
  • 17
  • 29
whatever
  • 386
  • 4
  • 6
  • 3
    So, When I change the `BasicRuntimeChecks` options to `Default`, the Debugger ignores the debug-points. In this case, I can't debug the codes line-by-line. – Dentrax Mar 25 '18 at 11:28