Compiling C++ Code

This lesson explains how to compile your code in C++, which compilers to use and the most suitable ones for different Operating Systems.

We'll cover the following

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.

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++11 and FreeBSD fully support clang and C++11.

However, many people prefer to use

For MacOS X, there is

  • Xcode which uses gcc for compiling C++.

For Windows, there is

and ports of the GNU Compiler Collection distributed within

You might also enjoy using

Each compiler is invoked in a specific way. For example, if you wish to use GCC, type the following into a terminal:

Create a free account to access the full course.

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