1.下载最新版ccache源码
wget https://www.samba.org/ftp/ccache/ccache-3.3.4.tar.gz
tar zxvf ccache-3.3.4.tar.gz
2.建立编译目录
mkdir ../build-ccache-3.3.4
cd ../build-ccache-3.3.4
3.配置生成Makefile
../ccache-3.3.4/configure
4.修改Makefile并编译
CFLAGS和CPPFLAGS修改参数:
CFLAGS = -g -O3 -Wall -W -march=native
CPPFLAGS = -g -O3 -Wall -W -march=native
make -j`getconf _NPROCESSORS_ONLN`
5.安装
sudo make install
6. 查看是否安装成功
ccache --version && which ccache && whereis ccache
> ccache version 3.3.4
> Copyright (C) 2002-2007 Andrew Tridgell
> Copyright (C) 2009-2017 Joel Rosdahl
> This program is free software; you can redistribute it and/or modify it under
> the terms of the GNU General Public License as published by the Free Software
> Foundation; either version 3 of the License, or (at your option) any later
> version.
> /usr/local/bin/ccache
> ccache: /usr/local/bin/ccache /usr/local/etc/ccache.conf
7. 创建软链接启用ccache
sudo ln -s /usr/local/bin/ccache /usr/local/bin/gcc
sudo ln -s /usr/local/bin/ccache /usr/local/bin/g++
sudo ln -s /usr/local/bin/ccache /usr/local/bin/cc
sudo ln -s /usr/local/bin/ccache /usr/local/bin/c++
8.配置
创建$HOME/.ccache/ccache.conf并添加
max_size = 5G
cache-dir = /dev/shm/tmp/ccache
查看
ccache -s
清理
ccache -C
9.使用
ccache gcc xx.c -o a.out
ccache make -j`getconf _NPROCESSORS_ONLN`
官网参考
https://ccache.samba.org/manual.html