首页 / 操作系统 / Linux / 在Linux CentOS上编译并安装Clang 3.5.0
编译CoreCLR需要Clang 3.5,而CentOS上安装的是Clang 3.4.2(yum repos中最新版也是这个),只能自己手工编译LLVM的源代码进行安装。(注:CentOS的版本是6.6)一、安装libstdc++4.7(注:如果是CentOS 7.0,不需要这步)wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repoyum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++ln -s /opt/rh/devtoolset-2/root/usr/bin/* /usr/local/bin/如果不安装,在configure配置编译选项时会出现下面的错误提示:We detected a missing feature in the standard C++ library that was known to bemissing in libstdc++4.6 and implemented in libstdc++4.7. There are numerousC++11 problems with 4.6"s library, and we don"t support GCCs or libstdc++ olderthan 4.7.二、安装Python 2.7.9(注:如果是CentOS 7.0,不需要这步)CentOS 6.6自带的是Python 2.6.6,而编译llvm需要Python 2.7以上。1)安装编译Python需要的包包yum install zlib-develyum install bzip2-develyum install openssl-develyum install ncurses-develyum install sqlite-devel2)下载并解压Python 2.7.9的源代码cd /optwget --no-check-certificate https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tar.xztar xf Python-2.7.9.tar.xzcd Python-2.7.93)编译与安装Python 2.7.9./configure --prefix=/usr/localmake && make altinstall4)将python命令指向Python 2.7.9ln -s /usr/local/bin/python2.7 /usr/local/bin/python三、添加交换分区如果编译的机器内存比较小,建议添加交换分区。我当时测试的机器只有1G内存,在编译过程中出现了“c++: internal compiler error: Killed (program cc1plus)”错误。1)创建并激活交换文件(比如2G): dd if=/dev/zero of=/swapfile bs=1k count=2048000mkswap /swapfileswapon /swapfile2)修改 /etc/fstab 文件让交换文件启动时自动加载,添加如下内容: /swapfile swapswapdefaults0 0四、编译LLVM1)下载llvm的源代码http://llvm.org/releases/3.5.0/llvm-3.5.0.src.tar.xzmv llvm-3.5.0.src llvm2)下载clang的源代码cd llvm/toolswget http://llvm.org/releases/3.5.0/cfe-3.5.0.src.tar.xztar xf cfe-3.5.0.src.tar.xzmv cfe-3.5.0.src clang3)下载compiler-rt的源代码cd ../projectswget http://llvm.org/releases/3.5.0/compiler-rt-3.5.0.src.tar.xztar xf compiler-rt-3.5.0.src.tar.xzmv compiler-rt-3.5.0.src compiler-rt4)配置编译选项cd ..
./configure --enable-optimized CC=gcc CXX=g++5)编译llvmmake -j2编译成功后的提示:llvm[0]: ***** Completed Release+Asserts Build6)安装编译好的llvmmake install会安装在/usr/local/bing中7)检查clang的版本# clang --versionclang version 3.5.0 (tags/RELEASE_350/final)如果还是旧版本,需要将/usr/bin/clang指向clang 3.5.0:ls -s /usr/local/bin/clang /usr/bin/clang更多CentOS相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14本文永久更新链接地址