Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article explains which compiler and linker switches to set to enable you to debug a release build of an application.
A better experience is available starting in Visual Studio 2022 version 17.14 that allows you to debug optimized code as if it were compiled unoptimized, while retaining the speed of optimized code. For more information, see C++ Dynamic Debugging (Preview).
To debug a release build
Open the Property Pages dialog box for the project. For details, see Set C++ compiler and build properties in Visual Studio.
Click the C/C++ node. Set Debug Information Format to C7 compatible (/Z7) or Program Database (/Zi).
Expand Linker and click the General node. Set Enable Incremental Linking to No (/INCREMENTAL:NO).
Under Linker, select the Debugging node. Set Generate Debug Info to Yes (/DEBUG).
Under Linker, select the Optimization node. Set References to No (/OPT:NOREF) and Enable COMDAT Folding to No (/OPT:NOICF).
You can now debug your release build application. To find a problem, step through the code (or use Just-In-Time debugging) until you find where the failure occurs, and then determine the incorrect parameters or code.
If an application works in a debug build, but fails in a release build, one of the compiler optimizations may be exposing a defect in the source code. To isolate the problem, disable selected optimizations for each source code file until you locate the file and the optimization that is causing the problem. (To expedite the process, you can divide the files into two groups, disable optimization on one group, and when you find a problem in a group, continue dividing until you isolate the problem file.)
Use /RTC to try to expose such bugs in your debug builds.
For more information, see Optimizing Your Code.