There are 2 main non-MSVC compilers you will interact with:
g++
clang++
The following instructions assume you have a build directory and have already run cmake
at least once.
By default, Linux uses the GCC compiler for C++, g++
. If you want to compile with clang, then you have first to install clang:
To configure CMake to use a different compiler, you define the CMake variable CMAKE_CXX_COMPILER:
To switch back:
Just like WSL and Linux, except clang is already installed.
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++-12
To configure CMake to use a different compiler, you define the CMake variable CMAKE_CXX_COMPILER:
To switch back:
Note The clang on macOS uses different standard include files, than the one on Linux (and WSL). So you will want to periodically use GitHub Codespaces to verify that your code has the correct include files for clang on Linux.