
Instead, we can define KIDDING on the command line to make it #define-d for all source files. We could just define KIDDING within the file itself, but maybe we want to use this definition in several places. If the KIDDING macro is defined, the source text in between will be included in the preprocessor output. The last pair of directives is #ifdef KIDDING and #endif. In our example, GOODBYE will be replaced by std::cout << "Goodbye World" << std::endl wherever it appears. We can then use that macro identifier in our source code, and it will be replaced by the reference text during preprocessing. This allows us to define a macro identifier that refers to some text, in this case another print statement. It does this recursively, so one #include file may itself #include several other files. The #include directive looks for the file that follows it (in this case iostream) and replaces the directive with the full text of that file. The compiler, named cl.exe, will be located in the install directory, somewhere similar to the following: To obtain a free copy, just install the latest version of Visual Studio and the compiler will be included. It was originally a standalone product, but it has since been folded into the Visual Studio package. This article will focus on MSVC and GCC, but the principles should translate well to Clang and other compilers.

However, the most common, by platform, are: There are several compilers in active use today. Other tools that are built on top (build systems, IDEs, etc.) are just there to make the drafting and compilation process more pleasant. Indeed, a compiler and a minimal text editor are all you need to write game-changing software. It often fades into the background, but make no mistake: the compiler is the most important tool in your toolbox. Know Your CompilerĪ compiler transforms your C++ code into binary machine instructions and addresses that can be understood by your computer.

Subject to interest and time, I may eventually make this into a longer series about build systems and tooling. This will give us a better understanding of the compilation process and the ways in which it can be configured. With that in mind, this article will show how to use the command line to compile (very rudimentary) C++ code. The only way to avoid becoming slaves to our creations is to understand how they work in the first place. This is a major convenience when it works, but it becomes an obstacle when you need to change anything. When using Unreal Engine 4 or another high level framework, the compilation of your C++ code is largely hidden from view.

There may come a day where technology has advanced to the point that we never need to worry about which flags are set for compilation, or which files are being included.
