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.
ReplyDeleteThank you!
ReplyDelete