Tools

Compiler

We officially support using the GCC compiler. We recommend using the version ≥ 10.0 to be able to make use of the ISO C++20 standard. Clang ≥ 10 should be also usable for most tasks. On Windows, most code should also work in MS Visual Studio 2019 16.8 and newer.

See Installing GCC 10 for more details on installation of GCC.

To use clang on the school computers (aisa and Linux workstations only), you have to add the gcc-10.2 module (or just gcc which is an alias for 10.2 now):

$ module add gcc

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

If you are building your homeworks with other compiler then GCC 10 please ensure your code can also be compiled with GCC 10 on aisa. We use GCC 10 on our evaluation machine.

Installing GCC 10

Ubuntu ≥ 20.04, Debian Unsable/Bullseye, Ubuntu 20.04 in Windows Subsystem for Linux

You need to install g++-10: sudo apt install g++-10. Then you should use g++-10 (and gcc-10) for compilation.

Older Ubuntu or Ubuntu in WSL

You have to add a PPA repository that contains GCC 10 to your system

$ sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa
$ sudo apt-get update
$ sudo apt-get install gcc-10

Then you should use g++-10 (and gcc-10) for compilation.

Archlinux

You just need to have gcc installed (which you probably already have if you are Archlinux user).

Other Linuxes

If your distribution does not support GCC 10, you can compile it (it is actually not too difficult in most cases, it just takes a lot of time). See compiling GCC 10 for more details.

Windows

GCC 10 seems to be unavailable for Windows, either use GCC 10 in Ubuntu using Windows Subsystem for Linux (with Ubuntu 20.04LTS), or use up-to-date MS Visual Studio 2019 and check that your homework compiles on Aisa.

macOS

Apple clang seems to be not up-to-date with LLVM clang, you will probably need to install GCC 10. It can be installed using Homebrew:

$ brew install gcc

CMake

To use our CMake build scripts you need at least CMake 3.12. On aisa and school Linux workstation you have to add module cmake (which contains CMake 3.18.3). On your machines, we recommend you use CMake ≥ 3.12.

If your compiler of choice is not available using command c++ (which usually aliases to g++), you should set cmake to use your compiler of choice, e.g., g++-10. This would normally look something like this (starting from the directory with sources):

mkdir _build
cd _build
cmake .. -DCMAKE_CXX_COMPILER=g++-10 -DCMAKE_C_COMPILER=gcc-10
make

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 gcc-10/g++-10. 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 other compiler, you can re-run it with the compiler setting commands (this will invalidate any other options you passed to CMake beforehand).

Alternatively, you can set defaults for all reasonably written make and CMake builds by setting the CC and CXX environment variables (perhaps in your .bashrc):

export CC=gcc-10
export CXX=g++-10

(This will not switch compiler in already configured builds that use CMake).

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++20

To use clang-tidy, you will need to have clang-tidy 10 installed. Please keep in mind that Clang does not support some features GCC does so clang-tidy might also not be fully usable for C++20. On FI computers, please use module add llvm to get reasonably new clang-tidy.

Installing clang-tidy

In most Linux distributions clang-tidy will be either part of the clang package (Archlinux), or in a separate package clang-tidy or clang-tidy-N where N is the version number (Debian/Ubuntu). If you want to install clang-tidy on Debian stable or Ubuntu older than 20.04, look at apt.llvm.org and install clang-tidy for the latest stable release of LLVM. You can probably use the automatic install script.

Dynamic analysis

Note: On Aisa, there is a virtual memory limit of 256GB – while this seems like something that cannot be a problem for our small programs, it actually is a problem for programs which use sanitizers. The reason for this is that sanitizers allocate large blocks of virtual memory (in the order of tens of terabytes). Sanitizers use this memory to associate shadow data to you allocations using arithmetics on addresses. Please note that virtual memory need not be actually used, so it is possible to allocate much more of it than there is physical memory on the system (this is called memory overcommit). Therefore, to make programs compiled with sanitizers work on Aisa, you need to reset the limit: ulimit -v unlimited. Please pay attention to the next note so you don’t allocate all memory available for students on Aisa (there is another limit in place that works on physical memory, but it is common to all users).

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 in Clang

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.↩︎