Visual Studio
Compiling C/C++ Code Using cl.exe
in Visual Studio 2019
Steps to Compile a C/C++ Program
1. Open the Developer Command Prompt for VS 2019
- Click Start and search for "Developer Command Prompt for VS 2019".
- Open it.
2. Navigate to Your Source Code Directory
3. Compile a Single C/C++ File
- For a C file:
- For a C++ file:
- If the compilation is successful, an executable (.exe) file will be generated.
4. Compile Multiple Files
a.exe
(default name) or file1.exe
(if file1.cpp
contains main()
).
5. Specify an Output Executable Name
6. Run the Compiled Executable
Additional Compiler Options
Enable Optimization (/O2
)
Enable Debugging (/Zi
)
Compile Without Linking (/c
)
.obj
file without producing an .exe
.