1. Create a directory for LLVM
$mkdir ~/llvm $cd ~/llvmInstall required dependencies (Note : my system is already setup for development so I cannot find out the exact packages required, if you know them post them as comments)
$sudo apt-get install build-essential2. Download the latest version of LLVM sources including clang (C frontend) and compiler RT from http://llvm.org/releases/download.html#3.1
$wget http://llvm.org/releases/3.1/llvm-3.1.src.tar.gz $wget http://llvm.org/releases/3.1/clang-3.1.src.tar.gz $wget http://llvm.org/releases/3.1/compiler-rt-3.1.src.tar.gz $wget http://llvm.org/releases/3.1/test-suite-3.1.src.tar.gz3. Extract the downloaded sources
$tar zxvf ./llvm-3.1.src.tar.gz $tar zxvf ./clang-3.1.src.tar.gz $tar zxvf ./compiler-rt-3.1.src.tar.gz4. Move folders to correct location. We start by renaming 'llvm-3.1.src' to 'llvm-3.1' and moving 'clang' inside the LLVM 'tools' folder and compiler-rt under the LLVM 'projects' folder. This is where LLVM expects them to be.
$mv ./llvm-3.1.src ./llvm-3.1 $mv ./clang-3.1.src ./clang $mv ./clang ./llvm-3.1/tools/ $mv ./compiler-rt-3.1.src ./compiler-rt $mv ./compiler-rt ./llvm-3.1/projects/5. Once everything is in place we create a separate folder for the build process
$mkdir ./build $cd ./build6. Now we start the actual configuration and compilation of LLVM inside the 'build' folder
$../llvm-3.1/configureIf there are any missing packages required to compile LLVM it will ask you here. If everything is ok we can go ahead and compile it and also keep track of the time taken. Note that all binaries are available in the 'build/Release+Asserts/bin' folder including llvm, clang, clang++
$time make ..... llvm[0]: ***** Completed Release+Asserts Build real 44m17.244s user 41m42.572s sys 2m5.592sThat's it ! We are done :)
7. To start using LLVM we have to include the binaries in our path. Add the following lines to your bash profile
$gedit ~/.bashrcAdd this line to the end of the file
export PATH=$PATH:~/llvm/build/Release+Asserts/binTo apply the new settings close the terminal and start a new one or you can do
$source ~/.bashrc8. Test a sample program
$cd .. $mkdir test $cd test $gedit test.cAdd the following lines of a simple C program and save it
#include <stdio.h> int main(void) { printf("Hello World from LLVM!\n"); return 0; }Compile it using clang the C frontend to LLVM
$clang test.c -o testRun it
$./test Hello World from LLVM!
This comment has been removed by the author.
ReplyDeleteI want to try to build beignet so I needed the LLVM too. I followed your steps for the 3.2 LLVM version on ubuntu 12.04 and it worked fine. The only thing that might be missing from your description is the clang compiler. Even if I renamed and copied the clang directory under the Tools, as you suggested, it seems that my system did not found it.
ReplyDeletesudo apt-get install clang
solves the problem!
Good work, thanks.
Installing clang using apt-get is not what you want. If you cant find clang the try to follow the guide again.
ReplyDeleteI don't know if it works for 3.1 but installed it on
ReplyDeleteUbuntu 12.10
Everything you mentioned in step 2,3,4 but with 3.3 inspite of 3.1
finally when i compile it using $clang test.c -o test it couldn't find clang
I have done everything as you mentioned but it doesnot work for 3.3
But when did sudo apt-get install clang it found it.
I am following the instruction and after time make I got 1 error make/config.mk file or directory does not exist. And similarly make/util.mk does not exist. I am trying to install clang and llvm 3.4
ReplyDelete