Ccache

From miki
Revision as of 17:28, 24 November 2022 by Mip (talk | contribs) (→‎Reference)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

According to the manpage, ccache is a fast C/C++ compiler cache. It works with the gcc and clang compilers (or alike).

Reference

Related

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"