clangformat源码安装 
时间: 2023-05-02 11:07:13 浏览: 95
clangformat是llvm项目中的一个工具,可以格式化C/C++代码。在安装clangformat之前,首先需要安装llvm/clang。具体步骤如下:
1. 安装依赖库
sudo apt-get install -y build-essential git cmake python3 #Ubuntu
yum install -y gcc gcc-c++ git cmake3 python3 #CentOS
2. 下载llvm和clang源代码
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout llvmorg-13.0.0
3. 构建llvm和clang
mkdir build
cd build
cmake -G "Unix Makefiles" ../llvm -DCMAKE_INSTALL_PREFIX=/usr/local
make -j$(nproc)
sudo make install
4. 配置环境变量
将/usr/local/bin目录添加到PATH环境变量中
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
5. 下载并编译clangformat
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout llvmorg-13.0.0
cd llvm/tools
git clone https://github.com/llvm/llvm-project.git clang
cd ..
mkdir build
cd build
cmake -G "Unix Makefiles" ../llvm -DCMAKE_INSTALL_PREFIX=/usr/local
make -j$(nproc)
sudo make install
现在,您可以在命令行中使用clang-format命令来格式化C/C++代码了。例如:
clang-format -i -style=Google source.cpp
-i选项表示在源文件中直接修改,而不是输出到终端。-style选项指定使用Google代码风格进行格式化。
相关推荐















