How to Compile with MSVC via Command Line
It is not always necessary to use the Visual Studio debugger on Windows.
Using the command line formerly seemed to be a nerd thing, but over time it was noticed that it is much more practical and easier than the graphical mode, in addition to having a Huge performance gain!
In this article we will see that you can use the
cl command from the MSVC compiler from Microsoft to compile your programs!
Pictures are not in English, but you can understand how the corresponding path in your language!
01. Open Developer PowerShell
First of all make sure you have Visual Studio installed.
To compile, just search for the word Developer PowerShell in the Windows Start Bar and choose the option: Developer PowerShell for VS 2019, remembering that in this case refers to the 2019 version of Visual Studio, but if you have the other version, the year/version number will appear. And click Open.
02. Navigate to your C/C++ file
In the image there is the use of the commands
cat by PowerShell, but use Developer PowerShell.
03. Compile your C/C++ file(s)
To compile just use the
cl command, as shown below:
And then to run, run the file name with a backslash:
04. Using Parameters for MSVC
There are also other parameters, however, the model used by MSCV is not always the use of dash
- but a slash, example for
O2 and others:
For more parameters run the command:
Alternative within Visual Studio
You can also open Developer PowerShell or even
CMD through Visual Studio, saving time-consuming use of the Graphical Debugger.
To do this, just click on:
Command Line >
Developer PowerShell or
Developer Command Prompt:
And use the same procedures listed above:
For more information go to: MSVC address.