visual studio builds with optimization flags even when disabled in options - c++

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?

Related

Is is possible to build codes using Bazel in Visual Studio?

I'm currently following this instruction to build C++ code with tensorflow.
What I want to do is to run the execution (binary) file with Visual Studio's debug mode.
To do this, I think I have to build a binary file via Visual Studio first so that I can set a breakpoint and execute the code line by line.
But problem is that building the code in VS is not that simple because it uses bazel command instead of g++.
Is is possible to build codes using Bazel in Visual Studio?
As of version 0.22.0, there is no plugin support for Visual Studio: see list of supported IDEs and editors.
There is, however, an API to build IDE plugins.
In the meantime, https://github.com/tmandry/lavender has been published. This is a project generator that generates a Visual Studio Solution file and project files given Bazel build files (WORKSPACE, BUILD, etc.). Also debugging works surprisingly well.

Can't build Assembly Language program in Visual Studio

I am trying to build an assembly language in Visual Studio 2013 using MASM. If I import an .asm file, it initially builds. However, the second I go to make changes to that file, most of the code is highlighted red. Visual Studio is treating this assembly program as a C++ file or similar. Even though I have the MASM box selected in Build Customization, the program will not build because it does not recognize the syntax.
Can anyone help?
Visual Studio includes ML.EXE (32 bit) and ML64.EXE (64 bit). I generally create a custom build step for each .asm file in a project. For VS 2015, I right click on source file name, ..., choose custom build tool, and I also set "excluded from build" to "No" , for all configurations. The options for custom build tool or custom build step are:
Example debug build:
Command Line: ml /c /Zi /Fo$(OutDir)\example.obj example.asm
Outputs: $(OutDir)\example.obj
Example release build:
Command Line: ml /c /Fo$(OutDir)\example.obj example.asm
Outputs: $(OutDir)\example.obj
If building a 64 bit program, use ML64 instead of ML.

Visual Studio 2012 C++ How to add compiler option in NMake project

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.

How to compile c++ libs using Microsoft C++ compiler without the IDE

I want to use Notepad and invoke the compiler and linker from the command prompt.
No IDE no make , nmake or anything like similar because I want to know the exact syntax required to do the following:
1. create a static library
2. create a dll
Yes, I have browsed the MSDN site but the examples I saw assume one is using the IDE which does a lot of setup behind the scenes
Pls Note: I know how to compile executables using cl also setting up the env using vcvarsall.bat. My question is about compiling static libraries and dlls.
I am using Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86.
Suggestions on to use some other compiler ( gcc, mingw, intel etc.) will not be helpful at the moment.
The C++ compiler is named cl. The compiler options are well-documented on MSDN. The linker is named link. The linker options are also well-documented on MSDN.
You'll need to run vcvarsall.bat to be able to build with the Visual C++ toolchain; this batch file sets up all the required environment variables and such. If you've installed Visual Studio, you should have a shortcut on your Start Menu entitled "Visual Studio Command Prompt." This shortcut will get you a command prompt and run that batch file.
For DLLs, pass the /c flag to cl.exe (which compiles but doesn't link), and pass the /DLL flag to link.exe. Instead of making an executable, it makes a DLL.
For static libraries, use the lib.exe program.
There are multiple approaches, all of which are handily documented in one place:
Visual C++ Concepts: Building a C/C++ Program
Building on the Command Line
Note that the build system completely changed between VC++ 2008 (which you're using) and VC++ 2010 (which is the current release).
A couple of minor things to add.
Personally I wouldn't use Windows batch files.
I would use nmake http://msdn.microsoft.com/en-us/library/dd9y37ha(v=vs.71).aspx building outside of visual studio is nmake's day job and that's the standard way to build visual studio projects for release say on a build machine, rather than in a development environment.
The other thing in nmake's favour is that if cross-platform is important to you then cmake ( http://www.cmake.org/ ) is a brilliant tool for dynamically creating Windows nmake files and non-Windows make files and it comes with ctest for running your unittests and selftests.
Advert over.

How can I debug a MinGW EXE with the Microsoft Visual C++ debugger?

How can I debug a MinGW EXE with the Microsoft Visual C++ debugger?
You can attach the Visual C++ debugger to any process running on the system (from the Visual C++ menu). But for being able to step through your source code Visual C++ would have to load the symbol file (.pdb if I remember correctly) and I don't think GCC generates those files.
Exists many Visual studio extensions such us: WinGDB, VisualGDB you can find it on the web. It allows you to debug as regular Visual Studio project. These projects are not free but it has full functional 30 days trial. It has some restrictions but it's good enough.
The Problem:
GCC compiler (ie MinGW's gcc) generates debug info with "-g" flag. The debug info is embedded into the generated executable. Windows' compiler, on the other hand, uses a peculiar ".pdb" format to store the debug info. For example, Microsoft Visual Studio's debugger needs not only the executable (.exe), but also its debug info (.pdb) to be available.
The Solution:
There is a small program that can extract .pdb files from executables compiled with gcc.
It is called cv2pdb, available at https://github.com/rainers/cv2pdb.
Download cv2pdb https://github.com/rainers/cv2pdb
Put the cv2pdb.exe somewhere in your path, maybe a custom bin folder, so that it will be accessible through the command line.
Compile your file as usual using MinGW's gcc compiler, with the "-g" flag, so that the debug info is included.
Simply run cv2pdb.exe on your executable.
cv2pdb out.exe
This will generate a out.pdb file in the same directory.
(If you have Microsoft Visual Studio installed) Open the executable directly in Microsoft Visual Studio
devenv out.exe
Note: This command simply opens the executable in Microsoft Visual Studio, without creating a project for it. In effect, you can use whatever text editor + build system you want to build your executable, and then use Visual studio only as a standalone debugger.