I'm using ccache
with git-worktree
. So many of the same files are shared across multiple directories. Problem is that ccache
doesn't check if the file is the same, and is compiled again. Is there a ccache
option that would allow it to check the cache across multiple source directories?

- 20,499
- 4
- 26
- 28
1 Answers
ccache (by default since version 3.3) adds the current working directory to the hash if -g
is used, which only makes it possible to get cache hits within the same source directory. Another similar issue is if you use absolute paths in compiler arguments, then you need to use the base_dir
configuration setting.
More details from the "Compiling in different directories" section in the ccache manual:
If you build with -g (or similar) to add debug information to the object file, you must either:
- use the
-fdebug-prefix-map=old=new
option for relocating debug info to a common prefix (e.g.-fdebug-prefix-map=$PWD=.
); or - set
hash_dir = false
.
- use the
If you use absolute paths anywhere on the command line (e.g. the source code file path or an argument to compiler options like
-I
and-MF
), you must to setbase_dir
to an absolute path to a “base directory”. ccache will then rewrite absolute paths under that directory to relative before computing the hash.

- 846
- 9
- 12