We officially support using the clang compiler. We recommend using the version 5.0 to be able to make use of the ISO C++17 standard. If you want to use a different compiler, please make sure that it has full ISO C++14 and reasonable ISO C++17 support. The following compilers should be OK to use: gcc  ≥ 7, clang  ≥ 4 (use -std=c++1z instead of -std=c++17 with clang 4).

To use clang on the school computers (aisa and Linux workstations only), you have to add the llvm-5.0.0 module:

$ module add llvm-5.0.0

This allows you to call the clang, clang++, and clang-tidy binaries. We suggest putting this command into your .bashrc file (and remove all conflicting llvm-x.x.x and gcc-x.x.x modules if possible).

If you want to try building with GCC 7, you can add module gcc-7.2. Keep in mind your code has to compile with clang 5 and clang and GCC can differ.


To use our CMake build scripts for homework you need at least CMake 3. On aisa and school Linux workstation you have to add module cmake-3.6.2.

CMake has to be configured to use clang. The normal CMake setup and build would be something like this (starting from the directory with sources):

mkdir _build
cd _build

The first two commands create a build directory and switch to it (it is recommended to build in a separate build directory, not in the source directory). The second one runs CMake and creates Makefile for you, setting the compiler to clang/clang++. The .. is the path to your sources. You should specify version if your default clang is not clang 5. Finally, make builds your project and produces binaries.

If you have CMake already configured with GCC, you can re-run it with the compiler setting commands (this will invalidate any other options you passed to CMake beforehand).

Static analysis

We recommend using the clang-tidy tool for static analysis and style checking. You may want to look at the list of clang-tidy checks we use.

$ clang-tidy -header-filter=.* filename.cpp -- -std=c++17

Dynamic analysis

Note: Do not run valgrind on code compiled with clang sanitizers, it is very likely to eat all available memory and freeze your computer entirely.

Standard Library

Clang is able to use two standard library implementations, libstdc++ (GNU project) and libc++ (LLVM project). The implementation it uses by default is the system one, which is usually libstdc++ (unless you are on OS X where libc++ is the default). It might sometimes make sense to try compiling with a different standard library implementation (i.e. because there might be some bugs in the default library or just because you want to try whether everything works OK even with a different library1). You can tell clang which library to choose via the -stdlib=libc++ or -stdlib=libstdc++ options. Of course, you need to have the desired library installed.

Warning: Using a different standard library than the default will not work if you link your code with another C++ libraries (everything that is to be linked together needs to be compiled with the same standard library).

  1. Trying to compile your code with different libraries may sometimes help spot header include errors.