利用 ccache 加速 c++ 程序构建

2022/1/16 tools

ccache 的基本原理是通过将头文件高速缓存到源文件之中而改进了构建性能,因而通过减少每一步编译时添加头文件所需要的时间而提高了构建速度。

# 安装

# 下载

前往官网下载页面下载源码:Ccache — Download (opens new window)

# 解压

遵循官方的安装指导 (opens new window)

tar -xf ccache-4.5.1.tar.gz
cd ccache-4.5.1
mkdir build
cd build
1
2
3
4

# 安装依赖

sudo apt install libhiredis-dev
1

# 构建

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/ ..
make -j 12
make install
1
2
3

# 使用

# 单独使用

ccache g++ helloWord.hpp -O helloWord.exe
1

# 与 cmake 协同:

-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
1
Last Updated: 2023-10-29T08:26:04.000Z