07. Compilation


C++ is a compiled programming language, which means that programmers use a program to compile their human-readable source code into machine-readable object and executable files. The program that performs this task is called a compiler .

C++ does not have an "official" compiler. Instead, there are many different compilers that a programmer can use.

GNU Compiler Collection (GCC)

In this program we primarily use the GNU Compiler Collection , which is a popular, open-source, cross-platform compiler from the larger GNU Project . In particular, we use the g++ program, which is a command line executable that compiles C++ source code and automatically links the C++ Standard Library .


C++ Compilation Process (Wikimedia)

C++ Compilation Process (Wikimedia)

In order to use classes and functions from the C++ Standard Library , the compiler must have access to a compiled version of the standard library, stored in object files. Most compiler implementations, including GCC, include those object files as part of the installation process. In order to use the Standard Library facilities, the compiler must "link" the standard library object files to the object files created from the programmer's source code.

Once the compiler links together the necessary object files, it is able to generate a standalone executable file that can run on the operating system.