Difference between revisions of "Clang"

From ArchWiki
Jump to: navigation, search
m (add CUDA)
m (style)
Line 5: Line 5:
 
[[zh-hans:Clang]]
 
[[zh-hans:Clang]]
 
[http://clang.llvm.org/ Clang] is a [[C]]/C++/Objective C/[[CUDA]] compiler based on [[LLVM]]. It is distributed under the BSD Licence.
 
[http://clang.llvm.org/ Clang] is a [[C]]/C++/Objective C/[[CUDA]] compiler based on [[LLVM]]. It is distributed under the BSD Licence.
 +
 
== Installation ==
 
== Installation ==
Install {{pkg|clang}} from the [[Official repositories]].
+
 
 +
Install the {{pkg|clang}} package.
  
 
== Build packages with Clang ==
 
== Build packages with Clang ==
 +
 
Add {{ic|1=export CC=clang}} and (for C++) {{ic|1=export CXX=clang++}} to your {{ic|/etc/makepkg.conf}}. If you are building with {{ic|debug}} also remove {{ic|-fvar-tracking-assignments}} from {{ic|DEBUG_CFLAGS}} and {{ic|DEBUG_CXXFLAGS}} as clang does not support it.
 
Add {{ic|1=export CC=clang}} and (for C++) {{ic|1=export CXX=clang++}} to your {{ic|/etc/makepkg.conf}}. If you are building with {{ic|debug}} also remove {{ic|-fvar-tracking-assignments}} from {{ic|DEBUG_CFLAGS}} and {{ic|DEBUG_CXXFLAGS}} as clang does not support it.
  
Line 14: Line 17:
  
 
== Using the Static Analyzer ==
 
== Using the Static Analyzer ==
 +
 
To analyze a project, simply place the word {{ic|scan-build}} in front of your build command. For example:
 
To analyze a project, simply place the word {{ic|scan-build}} in front of your build command. For example:
 
  $ scan-build make
 
  $ scan-build make

Revision as of 16:24, 17 August 2018

Clang is a C/C++/Objective C/CUDA compiler based on LLVM. It is distributed under the BSD Licence.

Installation

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:

$ scan-build make
Tip: If your project is already compiled, scan-build won't rebuild and won't 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

See also