Building LLVM and Clang

Often it’s useful to build the latest LLVM and Clang from source code, rather than relying on often out-of-date packages available in repositories. This build process can be done quickly and easily with CMake, but it’s worth taking care to ensure the right options are passed.

The following commands will build LLVM and Clang to be installed in /usr/bin (and /usr/lib, etc.). Note that the ‘-j’ option tells make how many recipes may execute at once; use this to your advantage to dramatically reduce the build time on multi-core machines!

The following directory structure is assumed:

/ -> clang -> clang-src
  -> llvm -> llvm-src

(I.e. both LLVM and Clang have been downloaded and moved to /llvm/llvm-src and /clang/clang-src respectively.)


pushd llvm
mkdir llvm-build
cd llvm-build
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release ../llvm-src
make -j4


pushd clang
mkdir clang-build
cd clang-build
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DCLANG_PATH_TO_LLVM_SOURCE=../../llvm/llvm-src -DCLANG_PATH_TO_LLVM_BUILD=../../llvm/llvm-build ../clang-src
make -j4