centos7源码编译安装clang5.0.2

首先安装cmake3

yum install -y cmake3

安装编译llvm/clang所需要的库和相关软件

yum install -y libedit-devel libxml2-devel ncurses-devel perl-Data-Dumper python-devel swig

下载llvm 5.0.2和clang 5.0.2源代码并放入指定路径

wget https://releases.llvm.org/5.0.2/llvm-5.0.2.src.tar.xz
tar -Jxf llvm-5.0.2.src.tar.xz
mv llvm-5.0.2.src llvm

wget https://releases.llvm.org/5.0.2/cfe-5.0.2.src.tar.xz
tar -Jxf cfe-5.0.2.src.tar.xz
mv cfe-5.0.2.src/ llvm/tools/clang

wget https://releases.llvm.org/5.0.2/compiler-rt-5.0.2.src.tar.xz
tar -Jxf compiler-rt-5.0.2.src.tar.xz
mv compiler-rt-5.0.2.src llvm/projects/compiler-rt

wget https://releases.llvm.org/5.0.2/libcxx-5.0.2.src.tar.xz
tar -Jxf libcxx-5.0.2.src.tar.xz
mv libcxx-5.0.2.src/ llvm/projects/libcxx

wget https://releases.llvm.org/5.0.2/libcxxabi-5.0.2.src.tar.xz
tar -Jxf libcxxabi-5.0.2.src.tar.xz
mv libcxxabi-5.0.2.src/ llvm/projects/libcxxabi

wget https://releases.llvm.org/5.0.2/libunwind-5.0.2.src.tar.xz
tar -Jxf libunwind-5.0.2.src.tar.xz
mv libunwind-5.0.2.src/ llvm/projects/libunwind

wget https://releases.llvm.org/5.0.2/lld-5.0.2.src.tar.xz
tar -Jxf lld-5.0.2.src.tar.xz
mv lld-5.0.2.src/ llvm/tools/lld

wget https://releases.llvm.org/5.0.2/lldb-5.0.2.src.tar.xz
tar -Jxf lldb-5.0.2.src.tar.xz
mv lldb-5.0.2.src llvm/tools/lldb

wget https://releases.llvm.org/5.0.2/openmp-5.0.2.src.tar.xz
tar -Jxf openmp-5.0.2.src.tar.xz
mv openmp-5.0.2.src llvm/projects/openmp

wget https://releases.llvm.org/5.0.2/polly-5.0.2.src.tar.xz
tar -Jxf polly-5.0.2.src.tar.xz
mv polly-5.0.2.src llvm/tools/polly

wget https://releases.llvm.org/5.0.2/clang-tools-extra-5.0.2.src.tar.xz
tar -Jxf clang-tools-extra-5.0.2.src.tar.xz
mv clang-tools-extra-5.0.2.src llvm/tools/clang/tools/extra

### 编译llvm 5.0.2/clang 5.0.2

cd llvm
mkdir build
cd build
cmake3 -G "Unix Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCLANG_DEFAULT_CXX_STDLIB=libc++ -DCMAKE_BUILD_TYPE="Release" ..
make -j4

安装llvm 5.0.2/clang 5.0.2

cp -r lib64/python2.7 lib/python2.7
make install
make install-cxx install-cxxabi
echo "/usr/local/lib" >> /etc/ld.so.conf.d/llvm-clang.conf
ldconfig
点赞