C++ disable optimization temporarily - c++

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.

Related

executable compiled with VS 2015 much slower than with 2013

I am writing a graphical application using SDL2. I started the project in VS 2013 and it ran with about 30 fps. Now with the exact same code in VS 2015 I only get 8 - 10 fps.
To make sure it wasn't caused by moving the solution to a newer Version of the IDE I created a completely new project and only copied the source files. I even compiled the SDL libraries in VS 2015 but still much slower.
Can I do something to get better Performance or do I have to use VS 2013?
Are you comparing Debug or Release builds? Assuming you are comparing Release builds, the most likely explanation is differing compiler optimization settings between VS2013 and VS2015. Visual Studio has a fairly large number of compiler flags that can impact performance. Look at the property pages for your project, particularly at the options under Configuration Properties -> C/C++ -> Optimization and see if there are differences. Make sure you are comparing properties for the same configuration (Release vs. Debug).
If you find a Debug build is much slower, it is possible there are extra security / debug checks enabled in your VS2015 solution that are not enabled under VS2013. Compare the other settings under Configuration Properties -> C/C++ and see if you can identify any differences.

Where is C++ /Zo in Visual Studio 2013 Update 3

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.

How to separate the dev and production *.sln for Visual Studio 2013 projects

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.

WDK C++ Project Needs to change debug compiler strictness

I'm relatively new at drivers with WDK and Visual Studio.
When I compile project in debug mode I get no warnings or errors and project compiles and runs fine. However, when I compile in release mode, compilation stops and I get an error stating that a warning was found and is being treated as an error. The details of this are dumped into a log file found at the project root dir.
What I would like to do is have the compiler in debug mode be as strict as the release mode compiler. Currently they are both at default. The release mode seems stricter. I am using VS 2010 and WDK. I'm not sure how to do this. It would be ideal if this setting was at the VS level and not at a per project level.
Also, It would be great if the warnings would show up in VS IDE instead of a log file.
Visual Studio has different configuration setting for debug and release mode.
Check whether do you have relevant configuration in project > project properties -> linker etc......
If there is mismatch between debug and release mode configuration then change it. This should work
--Ali Chachar
--Pakistan
There are code differences in the debug and release compilation that may lead to warnings unrelated to strictness of the compiler. Most noticeable is in the logs; in the release version KdPrint/KdPrintEx calls will be discarded. There is a good chance that some of your function input parameters are used for printing only and in case it's being omitted you'll end up with unused parameter warnings - this is the most frequent difference in debug vs. release compilations.
Even if you have a VS2010 solution, your driver isn't being compiled with the VS compiler but rather with the WDK compiler so VS settings are irrelevant here. You can migrate your solution to VS2012 which have driver support integrated.

How to set up a project in VS2010 that can also be compiled from within VS with a different compiler?

I have a Visual Studio 2010 project with C++ code that I want to run on 2 Systems. I develop,compile,debug, etc. it in Visual 2010 but also have a separate batchfile with which I can compile some of the classes for a different system.
How do I have to set up the configuration manager (or do whatever else is necessary) so that I can run,debug,etc. my project normally in vs2010 with mfc/win32 and then switch to another, new configuration where only a batch file is being executed from vs2010 (and no longer the vs2010 compiler) and the results of that are being shown in the output window ?
I got it working by creating a new configuration in the configuration manager where I selected any kind of platform (doesn't matter for this) and then excluded all files from build with their individual file properties. The compiler has nothing to do then. So I added a custom build step in the project settings where my batch file is being executed. Now whenever I switch to this configuration in the menu only my batch file is being run and I can easily switch back to my normal debug profile for developing, testing and debugging in vs2010. Its not that elegant but it works...