【C++】编译安装clang14
clang安装
安装依赖包:
sudo dnf groupinstall "Development Tools"
sudo dnf install cmake ninja-build python3 gcc-c++
下载clang进行编译安装:
# 克隆 LLVM 项目
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout llvmorg-14.0.6
# 构建目录
mkdir build && cd build
cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb;compiler-rt" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/clang-14
ninja -j20
ninja install
echo 'export PATH=/opt/clang-14/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
安装在目录/usr/local:
# 克隆 LLVM 项目
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout llvmorg-14.0.6
# 构建目录
mkdir build && cd build
cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb;compiler-rt" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local
ninja -j20
ninja install
clang-tidy-14设置:
ln -s /opt/clang-14/bin/clang-tidy /usr/local/bin/clang-tidy-14
然后测试:
clang-tidy-14 --version
如果没有 clang-format-14
,就:
ln -s /opt/clang-14/bin/clang-format /usr/local/bin/clang-format-14
然后测试:
clang-format-14 --version
[root@localhost bin]# cd /opt/clang-14/bin && In clang++ clang++-14
-bash: In: command not found
[root@localhost bin]# cd /opt/clang-14/bin && ln clang++ clang++-14
[root@localhost bin]# clang++-14 --version
clang version 14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/clang-14/bin