Compiling C++ Code

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

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 sort of ‘compromise’ language between the native language of the CPU (generally referred to as machine language) and the native language of the programmer (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 mid-point that is closer to how humans think and organize procedures but is still unambiguously translatable to the native machine language.

The compiler, therefore, is reading in the code written by the programmer and translating 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

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

  • The GNU Compiler Collection (GCC) has versions available for most systems and does a good job of implementing the ISO C++ standard.

  • The clang compiler has complete support for C++ and FreeBSD fully support 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

and 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