Introduction
Clang is a new C/C++/Objective-C/Objective-C++ compiler being developed on top of LLVM.
Advantages of using clang
- Clang has much better compilation speed than gcc.
- Clang usually provides much better diagnostics in case your code fails to compile, which means that you need to spend less time trying to understand what you should do to fix your code. It even goes further by suggesting the most likely fixes.
Check out this page for more reasons why clang provides better compiler diagnotics.
Building and Installing clang
The following steps work on Mac and Linux only. Note that the clang port is not ready for everyday use yet, so I won’t recommend you switching to clang if you’re on Windows. As of November 2013, the trunk of clang is unsuited for building Firefox. The 3.3 release works. (The release page has links to GPG signatures for the files downloaded in the guide below.)
mkdir /path/to/clang-build
cd /path/to/clang-build
wget https://llvm.org/releases/3.3/llvm-3.3.src.tar.gz
tar zxvf llvm-3.3.src.tar.gz
mv llvm-3.3.src llvm
cd llvm/tools
wget https://llvm.org/releases/3.3/cfe-3.3.src.tar.gz
tar zxvf cfe-3.3.src.tar.gz
mv cfe-3.3.src clang
cd ../..
mkdir build
cd build
../llvm/configure --enable-optimized --disable-assertions
make
Finally, you need to either run
sudo make install
or on Linux, you probably want to create a removable package instead:
sudo checkinstall --pkgname clang --pkgversion 3.3 --nodoc -y
At this point, clang should be installed to /usr/local. In order to use it, you should add the following two lines to your mozconfig file:
export CC=clang
export CXX=clang++
For more information, check out this page.