我正在使用 ccache 进行实验,但我不太确定我应该使用它。任何人都可以解释 ccache 可能导致错误行为的情况。或者我们应该总是使用 ccache 吗?任何得到 ccache 的人都在生成错误的目标文件或头文件的更改没有被考虑?
3 回答
I practically never have any issues while using ccache
. Sometimes (e.g. once a month or even less), I clean entirely its cache with ccache -C
.
I have more issues with complex Makefile-s than with ccache
.
To be short, don't bother, and when you suspect something, just run ccache -C
.
You obviously should avoid ccache
when you are benchmarking the compilation time. (You could pass -time
or -ftime-report
to gcc
or g++
in that case).
Addenda
I my opinion, ccache
should be at least configurable to disable caching for compilation using GCC plugins, because a GCC plugin could do anything (e.g. querying a database or webservice) which is not cachable. See this message.
你通过提出错误的行为很好地表达了你的问题。
如果使用不当,ccache 的错误行为可能会减慢您的编译速度。ccache 必须扫描文件以识别过去的编译,因此通过 ccache 进行实际编译比没有它时要慢。只有缓存命中更快。
当您经常重新编译相同的代码而不修改它时,ccache 很有用。它不会加速新代码或修改代码的编译。
我曾经遇到过通过 ccache(符号链接方法)编译 SCons 的问题。
环境设置
事实证明,ccache需要在环境中设置 $HOME 变量,而 SCons 默认情况下不设置它(SCons 有策略在默认情况下尽可能地将构建与环境隔离)。
我不完全确定这是否会算作 ccache 的问题,或者仅仅是与 SCons 的互操作。除了这个怪癖之外,我在使用 ccache 时从来没有遇到过任何问题。
SSD 磨损
我养成了将 ~/.ccache 链接到 tmpfs 的习惯,以避免不必要地磨损我的 SSD。显然,这不是 ccache 的问题,因为没有它,情况会更糟。(只是要记住的一点)