Clang

From ArchWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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".

Installation

Install the clang package.

Build packages with Clang

Add export CC=clang and (for C++) export CXX=clang++ to your /etc/makepkg.conf and for LTO support: Install the lld package, then add -fuse-ld=lld to LDFLAGS in your /etc/makepkg.conf. If you are building with debug, also remove -fvar-tracking-assignments from DEBUG_CFLAGS and DEBUG_CXXFLAGS as Clang does not support it.

NB: For packages that specify GCC-specific build options, there may be build errors that require either editing the source package, the PKGBUILD or commenting out the Clang lines in makepkg.conf.

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 -B switch:

$ scan-build make -B

It is also possible to analyze specific files:

$ scan-build gcc -c t1.c t2.c

Tips and tricks

Bash completion

In order to enable Bash completion, install bash-completion and source /usr/share/clang/bash-autocomplete.sh in a Bash startup file.

See also