LLVM | LLVM Installation On Ubuntu
by Botao Xiao
Prerequest
- Git, to download source code and related materials.
- LLVM source code, from its github mirror.
- cmake, tool to compile and install LLVM.
- Clang, compiler created with LLVM. We can have this source code for clang from its github mirror.
Download source code for LLVM realated projects
- Download source code from github.
git clone https://github.com/llvm/llvm-project.git
- Add Clang to LLVM tools
cp -rf clang ./llvm/tools
- Compile and install LLVM, need to be attention that LLVM cannot be compiled in root of program, so we need to create a directory build.
- -G: generator
- DCMAKE_INSTALL_PREFIX: final path
- DCMAKE_BUILD_TYPE: could be debug or Release etc.
- Options for compiling LLVM
mkdir build cd build cmake -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD=host -DCMAKE_INSTALL_PREFIX=/usr/local/llvm -DCMAKE_BUILD_TYPE=MinSizeRel -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DCLANG_INCLUDE_TESTS=OFF .. make -j10 # modify accourding to your cpu lcore number. make install
- Add ENVIRONMENT to bash file. e.g export CPLUS_INCLUDE_PATH=/usr/local/llvm/include
My Installation Script, run in administrator
# !/bin/bash
# This is a bash file to install LLVM on unbuntu. Run in administrator mode(root).
echo --------------------------------------------------------------------------
echo STEP 1: Preparation. Update apt and install Cmake and git
echo --------------------------------------------------------------------------
apt update
apt install cmake
apt install git
echo --------------------------------------------------------------------------
echo STEP 2: Download source code of LLVM.
echo --------------------------------------------------------------------------
# Please change to your desired directory from root.
LLVM_ROOT='/home/xiaob6/test'
if [ ! -d '$LLVM_ROOT' ];then
mkdir $LLVM_ROOT
else
echo [$LLVM_ROOT] has already existed.
exit 1
fi
cd $LLVM_ROOT
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
cp -rf clang ./llvm/tools
echo --------------------------------------------------------------------------
echo STEP 3: Compile and install LLVM
echo --------------------------------------------------------------------------
cd ./llvm
mkdir build
cd build
cmake -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD=host -DCMAKE_INSTALL_PREFIX=/usr/local/llvm -DCMAKE_BUILD_TYPE=MinSizeRel -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DCLANG_INCLUDE_TESTS=OFF ..
make -j10 # modify accourding to your cpu lcore number.
make install
Subscribe via RSS