Sunday, February 17, 2013

How to build llvm from source on ubuntu 12.04

So I needed to build the latest llvm i.e. version 3.2 from source today. In this post I will describe the steps for Ubuntu 12.04.

First download the llvm source package from this link. I downloaded the x86 version because I am running 32 bit version of Ubuntu(aka i386).
Link: 32 bit

You can download the x86_64 version if you are running 64 bit Ubuntu(aka amd64).
Link: 64 bit

Put the downloaded .tar.gz archive in a convenient location. I put mine on ~/opt. Then extract the archive via this command.

cd ~/opt
tar xvzf clang+llvm-3.2-x86-linux-ubuntu-12.04.tar.gz

Now you will have a directory named LLVM. Go to the llvm directory.

cd LLVM
cd llvm
Now here comes the tricky part. The first time I ran this command


./configure --enable-optimized

and was greeted with the following error at the end:

configure: error: Selected compiler could not find or parse C++ standard library headers.  Rerun > with CC=c-compiler CXX=c++-compiler ./configure ...
The main purpose of this post is so that others can get rid of this specific error. Run the following command to get rid of the above error. You should have clang installed on your computer for this to work.

sudo apt-get install clang
./configure --enable-optimized CC=/usr/bin/clang CXX=/usr/bin/clang++

We have run the configuration script. Next step is to run the make command to start the building process. I should warn you that this is going to take a lo..ng time to finish.

make
After make finishes building run this final command to install.

sudo make install
References:

6 comments:

  1. Excellent blog post, you saved me a bunch of research - today I managed to build Clang for the first time!

    Kudos.

    ReplyDelete
    Replies
    1. Thanks! I'm glad it was helpful, motivates a lazy blogger like me :)

      Delete
  2. the link you provide do not have source code inside.
    how can i 'make' or 'configure'
    thanks
    can you provide me a link for the full source code with both clang and llvm,thanks very much.

    ReplyDelete
  3. Thanks for the help. The error message led me to believe that CC and CXX were environment variables instead of command line arguments X_X

    ReplyDelete
    Replies
    1. CC and CXX aren't command line arguments actually.

      CC refers to the system c compiler.
      CXX refers to the system c++ compiler

      You might find this helpful.

      http://stackoverflow.com/questions/11394659/where-does-the-value-of-cxx-in-a-makefile-come-from

      Delete