Compilers

There are 2 main non-MSVC compilers you will interact with:

The following instructions assume you have a build directory and have run cmake at least once.

Note that there is nothing magic about building in a "build" subdirectory. The name of the build directory can be anything you want. Consider having multiple build directories, one for GCC and one for Clang.

WSL and Linux

Linux uses the GCC compiler for C++, g++ by default. If you want to compile with clang, then you have to install it:

To configure CMake to use a different compiler, you define the CMake variable CMAKE_CXX_COMPILER:

To switch back:

GitHub Codespaces

Just like WSL and Linux, except clang is already installed.

macOS

By default, macOS uses clang. Even the command g++ is a clang compiler. To compile with GCC, you install gcc:

This will give you a version of the GCC C++ compiler. Right now, it is g++-13

To configure CMake to use a different compiler, you define the CMake variable CMAKE_CXX_COMPILER:

To switch back:

Note Clang on macOS uses Clang's standard C++ include files, while clang on Linux (and WSL) typically uses GCC's standard C++ include files. So you will want to periodically use GitHub Codespaces to verify that your code has the correct include files for clang on Linux.