If you develop C++ programs on Windows, you might have felt the need to invoke the compiler from the command prompt itself. Its pretty easy to do so; just append the path of the compiler to the
PATH environment variable.
However, if you decide to invoke it with some compiler/linker options, you’ll need to do some extra work.
Unlike Linux, it is a bit tricky to create permanent aliases on Windows as it requires editing the registry.
Before discussing on how to do it on Windows, let me first illustrate how it is done on Linux (Ubuntu specifically):
Suppose you want to set
c+ as an alias to
c++ -Wall -Wextra, simply create a file in your home folder named
.bash_aliases and write the following in it:
alias c+ = 'c++ -Wall -Wextra'
Instead of writing the compiler options
-Wall -Wextra directly, I prefer writing them in a separate file and then include them by specifying its path via the
@file option of the GCC compiler, so that I don’t have to write them again in my IDE’s settings.
.bash_aliases now contains the following:
alias c+ = 'c++ @/path/to/cpp-options.txt'
Now you can invoke the compiler by typing the following in a
Just like in the Linux case, we have to somehow instruct
cmd to launch the
doskey command every time it starts.
To do this, we need to create 2 files:
cmd_aliases.txt, which will contain all the aliases:
$*option is to allow the use of other command-line options along with
c+command. Without it, you won’t be able to specify the source-code and the output executable path when invoking the compiler with
cmd_autorun.cmd, which loads all those aliases from the above file everytime
[I am assuming these 2 files are kept in your
My Documents folder, although you can keep them in any other folder you like.]
Now we need to specify the location of this script in the registry so that it launches automatically along with
To do this, execute the following after pasting it to a text file and saving it with
For completeness, here are all the files which I use myself: