Ccache的编译速度加速

May 07, 2020 | 0 Minute Read

c++的编译真的是太慢了, ccache说是能提高编译速度,安装ccache会在/usr/lib64/ccache目录创建工具的链接

[root@localhost]# ls  -lh /usr/lib64/ccache/
total 0
lrwxrwxrwx. 1 root root 16 Apr  9 15:12 c++ -> ../../bin/ccache
lrwxrwxrwx. 1 root root 16 Apr  9 15:12 cc -> ../../bin/ccache
lrwxrwxrwx. 1 root root 16 Apr  9 15:12 clang -> ../../bin/ccache
lrwxrwxrwx. 1 root root 16 Apr  9 15:12 clang++ -> ../../bin/ccache
lrwxrwxrwx. 1 root root 16 Apr  9 15:12 g++ -> ../../bin/ccache
lrwxrwxrwx. 1 root root 16 Apr  9 15:12 gcc -> ../../bin/ccache
lrwxrwxrwx. 1 root root 16 Apr  9 15:12 x86_64-redhat-linux-c++ -> ../../bin/ccache
lrwxrwxrwx. 1 root root 16 Apr  9 15:12 x86_64-redhat-linux-g++ -> ../../bin/ccache
lrwxrwxrwx. 1 root root 16 Apr  9 15:12 x86_64-redhat-linux-gcc -> ../../bin/ccache

所以先执行

declare -x PATH="/usr/lib64/ccache:$PATH"

再编译就会使用ccache,ccache默认创建的缓存会放到个人$HOME目录 ~/.ccache 这个位置里面去。

其实centos 8安装完他默认就启用了,要禁用ccache需要在自己的~/.bash_profilew文件里面 export CCACHE_DISABLE=1 禁用了才行

[root@localhost ]# cat /etc/profile.d/ccache.sh 
# Use ccache by default.  Users who don't want that can set the CCACHE_DISABLE
# environment variable in their personal profile.

试了一个实际的项目,编译速度从4分钟左右降到2分钟左右吧。

man ccache

https://github.com/ccache/ccache/blob/master/doc/MANUAL.adoc