Installing clang++ from Source

This document describes how to install clang++ from source. The full details are in the LLVM documentation (look, in particular, at the Getting Started with the LLVM System document). The purpose of this document is to distill that information into a short, easily digestible form.

This document assumes you are using a Linux or some other Unix-like system. Please refer to the official documentation above if you want to install clang++ on Windows. Follow the steps below.

  1. LLVM and clang++ are written in C++, and you'll need a C++ compiler to bootstrap them. Normally you would use g++. Use the command

            $ which g++
        

    to see if you have g++ installed. If you see no output you'll need to install g++ using your system's package manager.

  2. Download LLVM from the official LLVM Releases web page. At the time of this writing, the most recent version of the system is version 3.3. You need three components: Clang source code, LLVM source code, and Compiler RT source code.

  3. Unpack the LLVM source code in some suitable place. It should create a directory named something like llvm-3.3.src.

  4. Unpack the Clang source code and move the directory created into llvm-3.3.src/tools. Rename the directory to just clang (take away any version number, etc).

  5. Unpack the Compiler RT source code and move the directory created into llvm-3.3.src/projects. Rename the directory to just compiler-rt (take away any version number, etc). This step and the previous step put these auxiliary projects into a location where they will be automatically found and built by the main LLVM build system.

  6. Create a directory to hold the result of the build. I suggest llvm-3.3.bld as a sibling of llvm-3.3.src. All build artifacts will be put into this directory leaving the source directory in a pristine state.

  7. Change into your build directory and do

            $ ../llvm-3.3.src/configure --prefix=path/to/installation
          

    Replace path/to/installation with the location where you would like the system ultimately to be installed. If you leave off the --prefix option it will default to /usr/local. Often this is fine but you may wish to install the system somewhere under your home directory instead (for example). In any case be sure the bin directory beneath the installation prefix is on your PATH. If this is not the case you won't be able to execute the programs once they are installed.

  8. when configure completes run make in the build directory to compile everything. If you have a multicore processor, you can speed up the build by running parallel instances of the compiler. Use

            $ make -j n
          

    where n is the number of parallel instances to run (try using the number of cores you have). Fully building everything takes a long time.

  9. Once the system has finished building run make check to run the LLVM unit tests. This will give you some confidence that it built correctly. Note that this only tests the LLVM infrastructure. This step does not test the clang compiler.

  10. Run make install to install everything to the location you specified previously with the --prefix option. You may need to become root to do this step depending on where you are installing the system (if you are installing to your home directory, you can do everything under your normal user account). You are now ready to program using LLVM and clang!


Last Revised: 2013-08-31
© Copyright 2013 by Peter Chapin