我如何设置ccache?

我想使用ccache来加速编译。 我遇到了如何启用ccache

这是我到目前为止所做的:

$ sudo apt-get install -y ccache $ dpkg -l ccache ii ccache 3.1.6-1 Compiler cache for fast recompilation of C/C++ code $ whereis ccache ccache: /usr/bin/ccache /usr/lib/ccache /usr/bin/X11/ccache /usr/share/man/man1/ccache.1.gz 

我通过添加到~/.bashrc将ccache添加到路径中

 $ export PATH="/usr/lib/ccache:$PATH" $ source ~/.bashrc $ echo $PATH /usr/lib/ccache:/usr/local/cuda-5.5/bin/:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games 

符号链接看起来很好:

 $ ll /usr/lib/ccache/ total 76 drwxr-xr-x 2 root root 4096 mai 22 10:48 ./ drwxr-xr-x 253 root root 69632 mai 22 10:48 ../ lrwxrwxrwx 1 root root 16 mai 22 10:48 avr-g++ -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 avr-gcc -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 avr-gcc-4.5.3 -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 c++ -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 c89-gcc -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 c99-gcc -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 cc -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 g++ -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 g++-4.6 -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 gcc -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 gcc-4.6 -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 x86_64-linux-gnu-g++ -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 x86_64-linux-gnu-g++-4.6 -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 x86_64-linux-gnu-gcc -> ../../bin/ccache* lrwxrwxrwx 1 root root 16 mai 22 10:48 x86_64-linux-gnu-gcc-4.6 -> ../../bin/ccache* 

链接看起来不错:

 $ which g++ /usr/lib/ccache/g++ $ make g++ -o affine_euler affine_euler.cpp -O3 -DEIGEN_NO_DEBUG -I/usr/include/eigen3 g++ -o test_eigen test_eigen.cpp -O3 -DEIGEN_NO_DEBUG -I/usr/include/eigen3 

但是缓存是空的:

 $ ccache -s cache directory /home/dell/.ccache cache hit (direct) 0 cache hit (preprocessed) 0 cache miss 0 files in cache 0 cache size 0 Kbytes max cache size 1.0 Gbytes 

我哪里错了?

安装:

 # Install package sudo apt install -y ccache # Update symlinks sudo /usr/sbin/update-ccache-symlinks # Prepend ccache into the PATH echo 'export PATH="/usr/lib/ccache:$PATH"' | tee -a ~/.bashrc # Source bashrc to test the new PATH source ~/.bashrc && echo $PATH 

您的路径(至少在开头)应如下所示:

 /usr/lib/ccache:/usr/local/cuda-5.5/bin/:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games 

g++ / gcc现在应该指向:

 which g++ gcc /usr/lib/ccache/g++ /usr/lib/ccache/gcc 

配置:

如果您不希望限制文件数和缓存大小:

 ccache -F 0 ccache -M 0 

显示缓存统计信息

ccache -s

清空缓存并重置统计信息:

ccache -C -z

用法:

每次调用gccg++ ; ccache被调用。 我的错误是我没有删除已编译的文件。 只需删除所有CMake /输出文件,然后重新配置/编译。

那你的ccache不应该是空的。 现在尝试make clean and make ,你会发现它比重新编译所有内容要快得多,这要归功于缓存。

你的$PATH看起来不正确; ccache的目录应该在那里。 赶紧跑:

 export PATH="/usr/lib/ccache/:$PATH" 

…再次尝试你的g++命令。 该目录中充满了调用ccache的代理命令。 这适用于大多数脚本。


如果你只是手动调用g++ (不像上面你正在使用make那样),你可以只添加命令:

 ccache g++ ... 

关于安装:我发现在Ubuntu 18.04上发布的默认设置不会捕获ccc++调用。 要在那里完全安装ccache,您需要

sudo apt-get install ccache sudo /usr/sbin/update-ccache-symlinks export PATH="/usr/lib/ccache/:$PATH"然后(由于更新的符号链接)也调用cc和c ++被捕获!