Date
Oct. 18th, 2024
 
2024年 9月 16日

Post: CentOS: Install Clang

Today is the A Memorial Day

CentOS: Install Clang

Published 12:06 Jun 24, 2016.

Created by @ezra. Categorized in #Technology, and tagged as #UNIX/Linux.

Source format: Markdown

Table of Content

本文主要关于在 CentOS 中安装 Clang 的相关步骤。

(以 CentOS 7 为例)

安装 libstdc++

如果你正在使用 CentOS 7 及以上的版本,请直接跳过此步骤。

wget https://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++
ln -s /opt/rh/devtoolset-2/root/usr/bin/* /usr/local/bin/

安装Python

如果你已经安装了 Python 2.7 及以上的版本,请直接跳过此步骤。

yum install zlib-devel
yum install bzip2-devel
yum install openssl-devel
yum install ncurses-devel
yum install sqlite-devel
cd /opt
wget --no-check-certificate https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz
tar xf Python-3.5.1.tar.xz
cd Python-3.5.1
./configure --prefix=/usr/local
make && make altinstall
ln -s /usr/local/bin/python3.5 /usr/local/bin/python

下载 LLVM 源代码

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

下载 clang 源代码

cd llvm/tools
wget https://llvm.org/releases/3.8.0/cfe-3.8.0.src.tar.xz
tar xf cfe-3.8.0.src.tar.xz
mv cfe-3.8.0.src clang

下载 compiler-rt 源代码

cd ../projects
wget https://llvm.org/releases/3.8.0/compiler-rt-3.8.0.src.tar.xz
tar xf compiler-rt-3.8.0.src.tar.xz
mv compiler-rt-3.8.0.src compiler-rt

配置编译选项

由于不允许在 LLVMSource Tree 中配置,所以我们随便进入一个路径

cd ~
/usr/local/bin/llvm/configure --enable-optimized CC=gcc CXX=g++

如果你执行上面指令后得到这样的提示:

error: g++|clang++|icc required but not found

那么你可能需要安装 G++:

yum install gcc-c++

编译 llvm

make -j2

根据这可能需要较长的时间,编译成功后的提示:

llvm[0]: ***** Completed Release+Asserts Build

安装 llvm

make install

LLVM 会安装在 /usr/local/bing 目录下。

检查 clang 版本

# clang --version
clang version 3.8.0 (tags/RELEASE_350/final)

如果还是旧版本:

ls -s /usr/local/bin/clang /usr/bin/clang
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询