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
This allows you to call the
clang-tidy binaries. We suggest putting this command into your
.bashrc file (and remove all conflicting
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 has to be configured to use clang. The normal CMake setup and build would be something like this (starting from the directory with sources):
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
.. 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).
valgrind is a tool suite of dynamic analysis tools. The most notable part of valgrind is memcheck that is able to discover memory errors (leaks, wrong memory access, uninitialized memory).
- The clang tool itself offers a range of sanitizers. Useful are mainly AddressSanitizer (invalid memory access & leaks,
-fsanitize=address), MemorySanitizer (uninitialized memory,
-fsanitize=memory), and UndefinedBehaviourSanitizer (
- Note however, that memory sanitizer can have problems tracking if memory is defined when it was set inside the standard library, for this reason, it is better to use valgrind for checking if memory values are properly defined.
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.
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=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).
Trying to compile your code with different libraries may sometimes help spot header include errors.↩