http://www.visualstudio.com/news/2014-aug-4-vs
Mentions a new compiler switch for better debugging with optimizations on but I can't for the life of me find it.
Does anyone know where it is and how to turn it on?
C++
/Zo Compiler Switch
/Zo is a compiler switch that generates richer debugging information
for optimized code (non /Od builds). This includes improved support
for debugging local variables. (Minimum edition: Express)
See the documentation on MSDN here: /Zo (Enhance Optimized Debugging). For command-line builds, just add /Zo to the build commands. To add /Zo to a project in Visual Studio, open the Property Pages dialog for the project, and navigate to Configuration Properties > C/C++ > Command Line in the tree view control. Add /Zo to the Additional Options edit box, then click OK. You should be good to go. New options like this usually don't get added to the Project Properties dialog UI until the next major revision, so you have to use the Additional Options box to see them in action.
Note that there are some incompatible options such as native Edit and Continue, but that's an unusual thing to do in Release mode anyway.
Related
When I change from debug to release mode in Visual Studio and the code is being optimized after debugging in Release Mode, can I see what the optimized code looks like? Or it is already a binary code that is optimized so Visual Studio itself doesn't optimize the code by rewriting it in C++, so there is no any C++ code that is my code but already rewritten for optimalization.
The following works for both Debug and Release builds:
Set a breakpoint on the line(s) of interest.
Launch your program under the debugger (F5).
When your program breaks, right-click and select 'Go To Disassembly'.
But just to say, the code generated by the compiler in Release mode is not always easy to follow so be prepared for some surprises.
[Edit] As per #paddy's comment above, make sure that you compile your project with debugging information included, otherwise none of this will work properly:
Project properties -> C/C++ -> General -> Debug Information Format = Program Database (/Zi)
I want to use openCV in my Qt project. But the release build crash and mixing release and debug causes bugs. So I made search and found that building openCV on my very computer setting the same flags (optimization flags) that my project may help.
So I used cmake to generate the openCV project, and open the openCV.sln in my visual studio. But even when I disable the optimization in the properties, the detailed log output shows me that there's /O2 in the cl.exe command line.
Any one get a solution? I don't know well how to use Visual Studio, maybe I can build project from command line?
How can I disable C++ compiler optimizations temporarily ?
Often need to do this for release builds while debugging. The project settings do help but they need to be changed each time for each project.
For Visual Studio
I tried compiler options in environment variables but the priority is the rightmost conflicting option so Visual Studio overrides any values I set by the project settings.(For eg. /Od set by me in the environment is overridden to /O3 added by the project settings)
For Eclipse
Again modifying the global settings for each project seems to be the only way. Multiple select doesn't show the optimization setting so I am forced edit multiple projects one by one.
In both VS and Eclipse you can add new build configurations, e.g. an "Unoptimized release" which has all the debug checks in the code removed (via NDEBUG macro), but also has optimization disabled for better debugging experience. This takes a little time to setup, but then switching optimization off is as easy as switching between debug and release build.
I've set up my application release process on Jenkins CI. The build command is:
"c:\Program Files (x86)\Microsoft Visual Studio
12.0\Common7\IDE\devenv.com" foo.sln /Rebuild "Release" /Out log.txt
The optimization flags (/LTCG /OPT:REF /OPT:ICF) are enabled in foo.sln.
When I development on my machine, I would like to disable those flags (so incremental build is available) in order to reduce the build time. My problem is I have to check out foo.sln from version control system (Perforce in my case), disable the flags. However, whenever I need to check in any changes to foo.sln, I have to toggle optimization flags before check-in and after submitted. So my local settings won't get checked in. Is there a way to make this process easier (avoid toggling the local settings)?
I found some similar questions on SO, but those are for Web.config/App.config. Not for foo.sln solution files.
Using different Web.config in development and production environment
How to select different app.config for several build configurations
A VS solution starts with two standard configurations, Debug and Release. If you need another one and Debug isn't good enough then just add it.
Use Build + Configuration Manager. Upper left combobox marked "Active Solution Configuration", pick "New". Give it a distinctive name and copy from Release. Change the settings you want to be different. Alter your build command accordingly.
I am currently modifying on a open-source project to suit my own need, however, the project to be built (or compiler) requires me to add a /EHsc option to cl.exe
I am using Microsoft Visual Studio 2012 to work on the project. I have been searching long enough but I cannot find the solution still.
Is it possible to add a flag via MS Visual Studio 2012? Because I saw the output log displaying that compiler (cl.exe) compiled with various flag in this project such as /nologo /c /WX.
How can I add the options to cl.exe with this IDE?
Project working on : SumatraPDF
[Edit #1] After reading the first answer provided below, this is the screen I got, it doesn't seem there is an option to do so.
Update: From the screenshot you posted, it seems the SumatraPDF project is NMake-based.
Therefore, you will have to add /EHsc to the build command line, using the NMake property page described here, or edit the Makefile directly.
Original, misguided answer follows:
Per MSDN:
To set this compiler option in the Visual Studio development
environment
Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.
Select the C/C++ folder.
Select the Code Generation property page.
Modify the Enable C++ Exceptions property.
Or, set Enable C++ Exceptions to No, and then on the Command Line
property page, in the Additional Options box, add the compiler option.