CentOS 6: Install LLVM/Clang

This article will describe installing LLVM/Clang.

1 Build and install LLVM/Clang

CentOS 6's GCC version is 4.4.7 and it cannot build LLVM 3.0 later. This article will use llvm-2.9-4.fc16.src.rpm in Fedora 16 which provides LLVM/Clang.

Download Fedora 16's src.rpm.

$ FEDORA=http://archives.fedoraproject.org/pub/archive/fedora
$ SRPMS=${FEDORA}/linux/releases/16/Everything/source/SRPMS
$ wget -q ${SRPMS}/llvm-2.9-4.fc16.src.rpm

Install package for building src.rpm

$ sudo yum install -y yum-utils rpm-build rpmdevtools

Install package dependencies of llvm-2.9-4.fc16.src.rpm.

$ rpm -i llvm-2.9-4.fc16.src.rpm
$ sudo yum-builddep -y rpmbuild/SPECS/llvm.spec

Build llvm-2.9-4.fc16.src.rpm and install LLVM/Clang.

$ rpmbuild --rebuild llvm-2.9-4.fc16.src.rpm
$ sudo yum localinstall -y ~/rpmbuild/RPMS/x86_64/llvm-* \
$ rm -rf llvm-2.9-4.fc16.src.rpm ~/rpmbuild

2 Execution result

LLVM/Clang works as below. You can install tools which uses Clang/LLVM like clang-complete.

$ llvm-config --version
$ clang --version
clang version 2.9 (tags/RELEASE_29/final)
Target: x86_64-redhat-linux-gnu
Thread model: posix