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.2
$wget http://llvm.org/releases/3.2/llvm-3.2.src.tar.gz $wget http://llvm.org/releases/3.2/clang-3.2.src.tar.gz $wget http://llvm.org/releases/3.2/compiler-rt-3.2.src.tar.gz3. Extract the downloaded sources
$tar zxvf ./llvm-3.2.src.tar.gz $tar zxvf ./clang-3.2.src.tar.gz $tar zxvf ./compiler-rt-3.2.src.tar.gz4. Move folders to correct location. We start by renaming 'llvm-3.2.src' to 'llvm-3.2' 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.2.src ./llvm-3.2 $mv ./clang-3.2.src ./clang $mv ./clang ./llvm-3.2/tools/ $mv ./compiler-rt-3.2.src ./compiler-rt $mv ./compiler-rt ./llvm-3.2/projects/5. Once everything is in place we create a separate folder for the build process
$mkdir ./build $cd ./buildThis is how the folder structure looks like
|-- build (currently we are here) |-- llvm-3.2 | |-- projects | | |-- compiler-rt | |-- tools | | |-- clang |-- clang-3.2.src.tar.gz |-- compiler-rt-3.2.src.tar.gz |-- llvm-3.2.src.tar.gz6. Now we start the actual configuration and compilation of LLVM inside the 'build' folder outside of the main source directory so as to keep the main source tree clean
$../llvm-3.2/configure --enable-sharedNote : There are various configuration flags for CPU architecture, optimize builds, threads, etc. Check them with the '--help' option.
$../llvm-3.2/configure --helpIf there are any missing packages required to compile LLVM it will ask you here.
7. If everything is good we can go ahead and compile it and also keep track of the time taken. After compilation all binaries are available in the 'build/Release+Asserts/bin' folder and libraries are available in the 'build/Release+Asserts/lib' folder.
$time make -j 3 ..... llvm[0]: ***** Completed Release+Asserts Build real 31m58.051s user 52m50.842s sys 2m37.610sGreat job so far, few more steps to go :)
8. Its good to run some test suites that comes along with LLVM to verify everything is working.
$make check-all9. To start using LLVM we have to include the LLVM binaries and libraries in our path.
To add the LLVM binaries
$gedit ~/.bashrcAdd this line to the end of the file
export PATH=$PATH:~/llvm/build/Release+Asserts/binTo add the LLVM libraries
sudo gedit /etc/ld.so.conf.d/llvm.confAdd this line to the file (replace <your_user_name> with your current username)
/home/<your_user_name>/llvm/build/Release+Asserts/libTo apply the new settings do
$source ~/.bashrc $sudo ldconfig10. To check whether the LLVM binaries and libraries are correctly set
$which clang ~/llvm/build/Release+Asserts/bin/clang $sudo ldconfig -p | grep LLVM libLLVM-3.2svn.so (libc6,x86-64) => ~/llvm/build/Release+Asserts/lib/libLLVM-3.2svn.so11. 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!
I followed these instructions, as well as running `sudo make install` at the end to have the binaries copied into `/usr/local`. I don't seem to have the BlocksRuntime available (when I run clang with the `-lBlocksRuntime` flag I get a message saying its missing). Is there more to the procedure to get compiler-rt working?
ReplyDeleteI ended up using this library as a solution: http://mackyle.github.com/blocksruntime/
DeleteNice walkthrough! Got me on the right track.
ReplyDeleteAnyone who gets a missing bits/c++config.h, run 'locate c++config.h', copy an apropriate path to the bits/ dir and do 'export CPLUS_INCLUDE_PATH=thatpath'. Still wont pass the check-all test, but it will find it when you compile your stuff.
I installed clang++ to update-alternatives, and I'd recommend doing that rather than setting PATH envs.
(sudo)
ln -s ~/llvm/build/Release+Asserts/bin/clang++ /usr/bin/clang++-3.2
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.2 20
update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 20
update-alternatives --config c++
and do the same for 'clang' towards 'cc'
Makes it easy to switch between compilers if need be. Just use c++/cc in build scripts
Thanks
ReplyDeleteThanks for the guidance!
ReplyDeleteStupid question: should there be an actual difference if i dont do the build and installation on home/llvm directory but rather in /usr/local/llvm ? If yes, can I copy them from /usr/local to home, once the building is done?
cheers
you can do the build / copy anywhere you want as long as you do the step 9 correctly.
ReplyDeleteThanx for the post.. Helped a lot!!!!
ReplyDeleteThank you so much..
ReplyDeleteI am Korean Student.
ReplyDeleteI appreciate your instruction for installing LLVM.
As I am beginner, this video is so useful.
I think that a lot of people have received help from this instruction.
Once again, Thank you so much ~
after step number 10 path for clang was shown as /usr/bin/clang is it normal??
ReplyDeletealso, I got
libLLVM-3.6.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libLLVM-3.6.so.1
libLLVM-3.4.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libLLVM-3.4.so.1
libLLVM-3.4.so (libc6,x86-64) => /home/ayesha/llvm/build/Release+Asserts/lib/libLLVM-3.4.so
Is this normal??
> after step number 10 path for clang was shown as /usr/bin/clang is it normal??
Deleteno. you already have a installed version of llvm on your system.
check the video
Delete@ ayesha...do a clean install of linux bcz purge coomands wont wor...and follow the updated http://clang.llvm.org/get_started.html...no need to cross-compile for ARM...normally all targets are supported in simple compile
DeleteHello Sir I don't know whether its Right to request here but can u please help me in building vellvm ?what might be the necessary step actually i m completely unaware about it
ReplyDeletehello sir
ReplyDeleteplease can u tell me
how to uninstall total llvm+clang from the system