Appendix: Compiling C++ Code

Learn about the compilation process and the different types of C++ compilers.

For the computer to execute the “Hello World” code you have written, it first needs to be compiled by a C++ compiler. The compiler translates the textual representation of the program into a form that a computer can execute more efficiently.

What the compiler does

In very broad terms:

The compiler is a translator that acts as an intermediary between the programmer and the CPU on the computer."

A high-level language like C++ is actually a compromise between the CPU’s native language (generally referred to as machine language) and the programmer’s native language (say, English).

Computers do not natively understand human languages, yet for someone to write computer code in the native language of the machine would be too difficult and time-consuming. Therefore, the purpose of the computer language itself is to define a midpoint that is closer to how humans think and organize procedures, but is still unambiguously translatable to the native machine language.

Therefore, the compiler reads the code written by the programmer and translates it into machine language code that the computer can execute directly.

C++ is a compiled language that is converted to machine language by the compiler. Beginner programmers will likely also come across the notion of interpreted languages and interpreters. Since this text covers C++, interpreted languages are not covered in detail.

Running the compiler

To finish the process, the code needs to be compiled with a compiler. But what if you don’t have one? The good news is that several good compilers are available for free.

  • The GNU Compiler Collection (GCC) has versions available for most systems and implements the ISO C++ standard well.

  • The clang compiler has complete support for C++, and FreeBSD fully supports clang and C++.

However, many people prefer to use Integrated Development Environment (IDE), which provides a user-friendly environment for developing programs.

For macOS X, there is: Xcode, which uses gcc for compiling C++.

For Windows, there is:

  • Dev C++, which also uses GCC for compiling C++.

  • Microsoft Visual C++ (and its free Express version)

  • TCLITE

Ports of the GNU Compiler Collection distributed within:

  • Cygwin and MinGW

You might also enjoy using:

  • Geany

Create a free account to access the full course.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy