This post explains how to set up a comfortable, command-line based development environment for C/C++ applications on Windows.
Acquire Visual Studio
Downloading Visual Studio and installing Windows development packages is the most reliable way to get your hands on cl
- Microsoft’s C/C++ compiler.
Microsoft’s gives you a downloader application instead of Visual Studio itself. Run it and install Visual Studio Community 20xx
. The default installation should come pre-configured with everything you need including MSVC (the offical name of the compiler. cl
is just the executable name), profiling/debugging tools, and ofc the IDE. However you might want to check Windows XX SDK as well.
Add vcvarsall
parent directoy to path
Navigate to where you installed Visual Studio and search for a script named vcvarsall
. It could for example be at: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build
To add it to path:
- Open the start menu
- Edit system environment variables
- Environment Variables…
- Path
- New
- Copy paste the directory here as a new entry
(Optional) Subst repo folder
The commandline application subst
allows you to take any directory on the filesystem and make it so it appears as a fake partition. I like to do this at the parent directory of my repo or project folder.
subst R: C:\Repo
Invoke build tools from the commandline
Now you should have everything you need to invoke Microsoft’s build utilities from the commandline. My workflow involves:
- Opening a terminal window
- Setting working directory to the project I want to work on
R:
cd {repo path}
- Initializing current terminal window for development
vcvarsall {architecture, eg. x64}
- Invoking
cl
for compiling source files,MSBuild
for building .sln solution files, ordevenv
to run Visual Studio IDE hooked to a specific executable for debugging purposes.
cl {c/c++ file}
devenv {executable_path}