Ccache
According to the manpage, ccache is a fast C/C++ compiler cache. It works with the gcc and clang compilers (or alike).
Reference
- https://ccache.dev/
- ccache on GitHub
- ccache manual.
- https://software.intel.com/en-us/articles/accelerating-compilation-part-1-ccache
- Related
- distcc, to spread compilation over several computers.
- sccache, a compiler-cache for Rust.
Install
On Debian / Ubuntu, ccache is available as a standard package:
sudo apt install ccache
To use ccache for compiling, just create a few symlinks. For instance, to use ccache with gcc and clang-3.6:
sudo ln -sf /usr/bin/ccache /usr/local/bin/gcc
sudo ln -sf /usr/bin/ccache /usr/local/bin/clang-3.6
This will work as long as the directory with symlinks comes before the path to the compiler (which is usually in /usr/bin).
Usage
- Collect ccache usage statistics:
ccache -s
- Set cache size:
ccache -M 2G
Troubleshoot
Get ccache logging
Enabling ccache logging may help troubleshooting issues. Just add to ~/.ccache/ccache.conf:
log_file = ccache.log
From now on, ccache will produce a detailed log in the current directory.
ccache ignore .include directive in assembly file
ccache ignores .include
directives in assembly file (*.s or *.S).
As a result, if the included file changes, ccache does not detect it and still provides the old object.
Workaround:
- Use
.incbin
directive instead [1]. The problem is that clang ignores.incbin
directive. The fix is to use a conditional compilation like:
# Pretend we use .incbin directive to prevent ccache to cache this file (clang ignores ;incbin, and ccache ignores .include)
.if 1
.include "file.s"
.else
.incbin "file.s"
.endif
- Better yet, use *.S file that enables preprocessor, and use a standard
#include directive
, which will be correctly catched by ccache:
#include "file.S"