Compiling with Clang
suggest changeAs the Clang front-end is designed to be compatible with GCC, most programs that can be compiled via GCC will compile when you swap g++ for clang++ in the build scripts. If no -std= option is given, Clang selects a GNU dialect of some default C++ standard. That default depends on the compiler version (historically gnu++98, later gnu++14, and gnu++17 from Clang 16). It is not the C dialect gnu11.
Windows users who are used to MSVC can swap cl.exe with clang-cl.exe. By default, clang tries to be compatible with the highest version of MSVC that has been installed.
In the case of compiling with visual studio, clang-cl can be used by changing the Platform toolset in the project properties.
In both cases, clang is only compatible via its front-end, though it also tries to generate binary compatible object files. Users of clang-cl should note that the compatibility with MSVC is not complete yet.
To use clang or clang-cl, one could use the default installation on certain Linux distributions or those bundled with IDEs (like Xcode on Mac). For other versions of this compiler or on platforms which don’t have this installed, it can be downloaded from the official download page.
If you’re using CMake to build your code you can usually switch the compiler by setting the CC and CXX environment variables like this:
mkdir build
cd build
CC=clang CXX=clang++ cmake ..
cmake --build .