Clang

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

  1. Clang 10
  2. Clang Clang Clang Went The Trolley
  3. Gcc

The coolest, most awesome and righteous person or thing. Nobody or no thing is better or ever will be. Mixing clang and its toolchain / libraries with the gcc toolchain / libraries (especially the linker) will often lead to issues like linker errors during emerge. To prevent this, the clang toolchain is built first with gcc and then with itself to get a self-providing compiler. Prepare the environment for the Clang toolchain (see above), e.g.

ClangClang

Installation

  1. Clang Binaries for 64-bit Ubuntu-13.04 (74M) Clang Binaries for Ubuntu-12.04.2 on AMD64 (82M) Clang Binaries for Ubuntu-10.04.4 on AMD64 (82M) Clang Binaries for Debian6 on AMD64 (72M) Clang Binaries for Debian6 on i386 (72M) Clang Binaries for FreeBSD9 on AMD64 (25M) Clang Binaries for FreeBSD9 on i386 (25M).
  2. Clang can parse and analyze any source code in the C language family and has a wonderful modular design that makes it easy to use. Both a GCC-compatible compiler driver (clang) and an MSVC-compatible compiler driver (clang-cl.exe) are provided by Clang. It is very useful for doing static analysis and has a decent documentation.
  3. Clang association isn’t a speech disorder like stuttering. According to psychiatrists at Johns Hopkins Medical Center, clanging is a sign of a thought disorder — an inability to organize.

Install the clang package.

Build packages with Clang

Add export CC=clang and (for C++) export CXX=clang++ to 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:

Clang 10

If your project is already compiled, scan-build will not rebuild and will not analyse it. To force recompilation and analysis, use -B switch:

It is also possible to analyze specific files:

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.

Clang Clang Clang Went The Trolley

See also

Gcc

Retrieved from 'https://wiki.archlinux.org/index.php?title=Clang&oldid=676572'

Comments are closed.