Compile from command line with Visual C++ [duplicate] - c++

This question already has answers here:
Compiling on the command line in Visual C++
(3 answers)
Closed 9 years ago.
I want to avoid the hassle of creating and building a project in Visual Studio to compile my program. I just want a Makefile, like you do with gcc for example, so that I can compile my program from command line. How can this be done.

Launch the Developer Command Prompt for VS2010 (I have VS2012, so maybe the name is slightly different for you. Mine is on the program menu under "Microsoft Visual Studio 2012->Visual Studio Tools".) This sets up search paths for you and is usually easier than working at the standard cmd.exe prompt.
Write your makefile. The name of the C++ compiler is cl. Use nmake to process your makefile.
If you want assistance on how to create a makefile, please ask that specifically.

just write a MAKEFILE, enter directory with it and type in cmd.exe or IDE command prompt:
>nmake
(more here). You can build a program using only compiler without makefile too:
>cl /EHsc simple.cpp
(use /EHsc to allow C++ exception handling) this will produce executable simple.exe (more here)

Related

how to setup Visual Studio Code for c++ for windows? [duplicate]

This question already has answers here:
How do I set up Visual Studio Code to compile C++ code?
(14 answers)
Closed 3 months ago.
So my teacher is wants the class to install C++, and I don't know how to do it. Please help me set it up in Visual Studio Code because it's the IDE I'm most familiar with. Please explain it in the simplest way possible.
I tried installing vscode and c++ extension but library files are missing
If you are going to edit and execute on Windows, you have to install either Visual Studio regardless or g++ under MinGW. These instructions are very detailed:
https://code.visualstudio.com/docs/languages/cpp
To configure VSCode with MS compiler:
https://code.visualstudio.com/docs/cpp/config-msvc
To configure VSCode with gcc on Windows:
https://code.visualstudio.com/docs/cpp/config-mingw
Another alternative that I recommend is to use Windows WSL which is like a Linux inside Windows.
https://code.visualstudio.com/docs/cpp/config-wsl
Then install the C++ extensions for VSCode.
Then I recommend you install cmake for Windows. Although the tutorials will teach you how to build a single file, you will need more for large projects.
https://cmake.org/install/
Create a CMakeLists.txt and then use the cmake-gui to create the Visual Studio project files. All this is outside Visual Studio Code.
To build from inside VSCode I found it particularly cumbersome. I'd rather Alt-Tab and build the project manually by either calling 'make' or building inside Visual Studio. But it's your preference.
But if you are editing on Windows and running on Windows, I'd strongly suggest to run inside Visual Studio itself. Not only you will have way more support for your questions but also the Visual Studio debugger is arguably the best in the market.

C++ Setup For VS Code [duplicate]

This question already has answers here:
How do I set up Visual Studio Code to compile C++ code?
(14 answers)
Closed 10 months ago.
So my teacher is wants the class to install C++, and I don't know how to do it. Please help me set it up in Visual Studio Code because it's the IDE I'm most familiar with. Please explain it in the simplest way possible.
If you are going to edit and execute on Windows, you have to install either Visual Studio regardless or g++ under MinGW. These instructions are very detailed:
https://code.visualstudio.com/docs/languages/cpp
To configure VSCode with MS compiler:
https://code.visualstudio.com/docs/cpp/config-msvc
To configure VSCode with gcc on Windows:
https://code.visualstudio.com/docs/cpp/config-mingw
Another alternative that I recommend is to use Windows WSL which is like a Linux inside Windows.
https://code.visualstudio.com/docs/cpp/config-wsl
Then install the C++ extensions for VSCode.
Then I recommend you install cmake for Windows. Although the tutorials will teach you how to build a single file, you will need more for large projects.
https://cmake.org/install/
Create a CMakeLists.txt and then use the cmake-gui to create the Visual Studio project files. All this is outside Visual Studio Code.
To build from inside VSCode I found it particularly cumbersome. I'd rather Alt-Tab and build the project manually by either calling 'make' or building inside Visual Studio. But it's your preference.
But if you are editing on Windows and running on Windows, I'd strongly suggest to run inside Visual Studio itself. Not only you will have way more support for your questions but also the Visual Studio debugger is arguably the best in the market.

Unable to debug c++ code in Visual Studio Code

I've just installed Visual Studio Code v1.7.1 to write my c++ code in for my degree. My programming level is pretty basic, but I like what I've seen of VS Code so far, save for the fact that I've no idea how to debug or build my code.
I've looked at a few questions on the topic, such as: How do I set up VSCode to compile C++ code?
and have tried implementing some of these into the tasks.json file, including the make command and the g++ command, but when I try and execute it I get the error:
'make' is not recognized as an internal or external command,
operable program or batch file.
or something similar. When I try running the debugger, it tells me to set up the launch.json file, so I entered the path of my file where it says 'program' as the instructions imply, I get the error
Unknown Error: 0x800700c1
I'm just looking for the simplest option that will allow me to write and debug code in vs code, in a manner similar to using the full version of visual studio, but without the heavy project filing system or the 10 minute loading times. Any help would be greatly appreciated.
What I deduce from your question and the comments is that you have no actual C++ compiler/buildchain installed. There are multiple compilers available (like minGW, GCC).
However, what Microsoft recommends is the following:
Installing C/C++ build tools
To obtain your set of C/C++ compilers on Windows you can grab the Visual C++ build tools SKU. By default these tools are installed at ‘C:\Program Files (x86)\Microsoft Visual C++ Build Tools’.
I have not tested, nor ever worked with the Visual C++ compiler, but it's probably the easiest way to get started right away.

Compile C++ to asm in Visual Studio [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to generate assembly code from C++ source in Visual Studio 2010
Hello.
How can I compile C++ code to asm in Visual Studio?
In gcc I just add one parampeter: -s
Looks like /FAs is the command-line argument. There is also a setting in the GUI: http://codegem.org/2008/10/generate-assembly-from-c-code-in-visual-studio
find project in solution explorer
right click properties
c/c++
output files
assembler output
If you want to generate it from the IDE, goto project properties > C/C++ > Output files. In that you have an option called "Assembler Output". By default its set to "No Listing". Pull down the menu and select the option that suits you.

Commandline app built with visual studio 9 does not take *.NEF as input while same app built with gcc does - why?

I built dcraw.c (http://www.cybercom.net/~dcoffin/dcraw/dcraw.c) as a windows command line application with cygwin / gcc before. Today I built it with visual studio 2008 as that allows including the libraries LIBJPEG and LCMS into the exe file and does not require the cygwin1.dll either. Also the VC built version seems to be faster. So much for the prelude.
The actual question is this: When I use the final application say as in dcraw -T -4 *.NEF
The cygwin / gcc built version will process all NEF files in my directory while the visual studio built one says: *.NEF: Invalid argument
I have no idea why that is and am looking for a way to fix this. Any help would be greatly appreciated.
I believe you need to add setargv.obj to be linked in. It will expand the wildcards. If you are using the command line (cl.exe), you can just specify it on the command line:
cl yourfile.c /link setargv.obj
In a Visual Studio project, you can add it to the Additional Dependencies field in the Linker Input options in the project properties.
Are you running both builds from the same type of command interpreter? On Unix systems, the shell expands wildcards; Windows cmd.exe doesn't, leaving it to the program to do if necessary. If you're running one build from cmd and the other from Cygwin's bash, that could explain the different behaviors.