Clang is a C/C++/Objective C/CUDA compiler based on LLVM. The most recent iteration is distributed under the "Apache 2.0 License with LLVM exceptions".
Build packages with Clang
To change the default compiler for building packages, edit:
... export CC=clang export CXX=clang++
libc++ as the C++ Standard Library instead of GCC's
libstdc++: install the libc++ package, then add
CXXFLAGS in your
For LTO support: install the lld package, then add
LDFLAGS in your
If you are building with
debug, you also need to remove
DEBUG_CXXFLAGS, as Clang does not support it.
Qt packages may require extra setup. Qt has predefined build configurations called "mkspecs", defaulting to GCC for Linux.
In some cases, mkspec will be automatically set to
linux-clang based on
But in other cases (e.g. packages with direct call of
qmake) it will not, so we can set it explicitly:
linux-clangis configured to use tools like
Using the Static Analyzer
To analyze a project, simply place the word
scan-build in front of your build command. For example:
$ scan-build make
If your project is already compiled,
scan-build will not rebuild and will not analyse it. To force recompilation and analysis, use
$ scan-build make -B
It is also possible to analyze specific files:
$ scan-build gcc -c t1.c t2.c
Tips and tricks
In order to enable Bash completion, install bash-completion and source
/usr/share/clang/bash-autocomplete.sh in a Bash startup file.