Compiling with Clang

suggest change

As the Clang front-end is designed for being compatible with GCC, most programs that can be compiled via GCC will compile when you swap g++ by clang++ in the build scripts. If no -std=version is given, gnu11 will be used.

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, this can be download 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 .

See also introduction to Cmake.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents