1CCACHE(1) ccache Manual CCACHE(1)
2
3
4
6 ccache - a fast C/C++ compiler cache
7
9 ccache [options]
10 ccache compiler [compiler options]
11 compiler [compiler options] (via symbolic link)
12
14 Ccache is a compiler cache. It speeds up recompilation by caching the
15 result of previous compilations and detecting when the same compilation
16 is being done again.
17
18 Ccache has been carefully written to always produce exactly the same
19 compiler output that you would get without the cache. The only way you
20 should be able to tell that you are using ccache is the speed.
21 Currently known exceptions to this goal are listed under CAVEATS. If
22 you discover an undocumented case where ccache changes the output of
23 your compiler, please let us know.
24
26 There are two ways to use ccache. You can either prefix your
27 compilation commands with ccache or you can let ccache masquerade as
28 the compiler by creating a symbolic link (named as the compiler) to
29 ccache. The first method is most convenient if you just want to try out
30 ccache or wish to use it for some specific projects. The second method
31 is most useful for when you wish to use ccache for all your
32 compilations.
33
34 To use the first method, just make sure that ccache is in your PATH.
35
36 To use the symlinks method, do something like this:
37
38 cp ccache /usr/local/bin/
39 ln -s ccache /usr/local/bin/gcc
40 ln -s ccache /usr/local/bin/g++
41 ln -s ccache /usr/local/bin/cc
42 ln -s ccache /usr/local/bin/c++
43
44 And so forth. This will work as long as the directory with symlinks
45 comes before the path to the compiler (which is usually in /usr/bin).
46 After installing you may wish to run “which gcc” to make sure that the
47 correct link is being used.
48
49 Warning
50 The technique of letting ccache masquerade as the compiler works
51 well, but currently doesn’t interact well with other tools that do
52 the same thing. See Using ccache with other compiler wrappers.
53
54 Warning
55 Use a symbolic links for masquerading, not hard links.
56
58 These command line options only apply when you invoke ccache as
59 “ccache”. When invoked as a compiler (via a symlink as described in the
60 previous section), the normal compiler options apply and you should
61 refer to the compiler’s documentation.
62
63 Common options
64 -c, --cleanup
65 Clean up the cache by removing old cached files until the specified
66 file number and cache size limits are not exceeded. This also
67 recalculates the cache file count and size totals. Normally, there
68 is no need to initiate cleanup manually as ccache keeps the cache
69 below the specified limits at runtime and keeps statistics up to
70 date on each compilation. Forcing a cleanup is mostly useful if you
71 manually modify the cache contents or believe that the cache size
72 statistics may be inaccurate.
73
74 -C, --clear
75 Clear the entire cache, removing all cached files, but keeping the
76 configuration file.
77
78 --config-path PATH
79 Let the subsequent command line options operate on configuration
80 file PATH instead of the default. Using this option has the same
81 effect as setting the environment variable CCACHE_CONFIGPATH
82 temporarily.
83
84 -d, --directory PATH
85 Let the subsequent command line options operate on cache directory
86 PATH instead of the default. For example, to show statistics for a
87 cache directory at /shared/ccache you can run ccache -d
88 /shared/ccache -s. Using this option has the same effect as setting
89 the environment variable CCACHE_DIR temporarily.
90
91 --evict-older-than AGE
92 Remove files older than AGE from the cache. AGE should be an
93 unsigned integer with a d (days) or s (seconds) suffix.
94
95 -h, --help
96 Print a summary of command line options.
97
98 -F NUM, --max-files NUM
99 Set the maximum number of files allowed in the cache to NUM. Use 0
100 for no limit. The value is stored in a configuration file in the
101 cache directory and applies to all future compilations.
102
103 -M SIZE, --max-size SIZE
104 Set the maximum size of the files stored in the cache. SIZE should
105 be a number followed by an optional suffix: k, M, G, T (decimal),
106 Ki, Mi, Gi or Ti (binary). The default suffix is G. Use 0 for no
107 limit. The value is stored in a configuration file in the cache
108 directory and applies to all future compilations.
109
110 -X LEVEL, --recompress LEVEL
111 Recompress the cache to level LEVEL using the Zstandard algorithm.
112 The level can be an integer, with the same semantics as the
113 compression_level configuration option), or the special value
114 uncompressed for no compression. See Cache compression for more
115 information. This can potentionally take a long time since all
116 files in the cache need to be visited. Only files that are
117 currently compressed with a different level than LEVEL will be
118 recompressed.
119
120 -o KEY=VALUE, --set-config KEY=VALUE
121 Set configuration option KEY to VALUE. See Configuration for more
122 information.
123
124 -x, --show-compression
125 Print cache compression statistics. See Cache compression for more
126 information. This can potentionally take a long time since all
127 files in the cache need to be visited.
128
129 -p, --show-config
130 Print current configuration options and from where they originate
131 (environment variable, configuration file or compile-time default)
132 in human-readable format.
133
134 -s, --show-stats
135 Print a summary of configuration and statistics counters in
136 human-readable format.
137
138 -V, --version
139 Print version and copyright information.
140
141 -z, --zero-stats
142 Zero the cache statistics (but not the configuration options).
143
144 Options for scripting or debugging
145 --checksum-file PATH
146 Print the checksum (64 bit XXH3) of the file at PATH.
147
148 --dump-manifest PATH
149 Dump manifest file at PATH in text format to standard output. This
150 is only useful when debugging ccache and its behavior.
151
152 --dump-result PATH
153 Dump result file at PATH in text format to standard output. This is
154 only useful when debugging ccache and its behavior.
155
156 --extract-result PATH
157 Extract data stored in the result file at PATH. The data will be
158 written to ccache-result.* files in to the current working
159 directory. This is only useful when debugging ccache and its
160 behavior.
161
162 -k KEY, --get-config KEY
163 Print the value of configuration option KEY. See Configuration for
164 more information.
165
166 --hash-file PATH
167 Print the hash (160 bit BLAKE3) of the file at PATH. This is only
168 useful when debugging ccache and its behavior.
169
170 --print-stats
171 Print statistics counter IDs and corresponding values in
172 machine-parsable (tab-separated) format.
173
174 Extra options
175 When run as a compiler, ccache usually just takes the same command line
176 options as the compiler you are using. The only exception to this is
177 the option --ccache-skip. That option can be used to tell ccache to
178 avoid interpreting the next option in any way and to pass it along to
179 the compiler as-is.
180
181 Note
182 --ccache-skip currently only tells ccache not to interpret the next
183 option as a special compiler option — the option will still be
184 included in the direct mode hash.
185
186 The reason this can be important is that ccache does need to parse the
187 command line and determine what is an input filename and what is a
188 compiler option, as it needs the input filename to determine the name
189 of the resulting object file (among other things). The heuristic ccache
190 uses when parsing the command line is that any argument that exists as
191 a file is treated as an input file name. By using --ccache-skip you can
192 force an option to not be treated as an input file name and instead be
193 passed along to the compiler as a command line option.
194
195 Another case where --ccache-skip can be useful is if ccache interprets
196 an option specially but shouldn’t, since the option has another meaning
197 for your compiler than what ccache thinks.
198
200 ccache’s default behavior can be overridden by options in configuration
201 files, which in turn can be overridden by environment variables with
202 names starting with CCACHE_. Ccache normally reads configuration from
203 two files: first a system-level configuration file and secondly a
204 cache-specific configuration file. The priorities of configuration
205 options are as follows (where 1 is highest):
206
207 1. Environment variables.
208
209 2. The primary (cache-specific) configuration file (see below).
210
211 3. The secondary (system-wide read-only) configuration file
212 <sysconfdir>/ccache.conf (typically /etc/ccache.conf or
213 /usr/local/etc/ccache.conf).
214
215 4. Compile-time defaults.
216
217 As a special case, if the the environment variable CCACHE_CONFIGPATH is
218 set it specifies the primary configuration file and the secondary
219 (system-wide) configuration file won’t be read.
220
221 Location of the primary configuration file
222 The location of the primary (cache-specific) configuration is
223 determined like this:
224
225 1. If CCACHE_CONFIGPATH is set, use that path.
226
227 2. Otherwise, if the environment variable CCACHE_DIR is set then use
228 $CCACHE_DIR/ccache.conf.
229
230 3. Otherwise, if cache_dir is set in the secondary (system-wide)
231 configuration file then use <cache_dir>/ccache.conf.
232
233 4. Otherwise, if there is a legacy $HOME/.ccache directory then use
234 $HOME/.ccache/ccache.conf.
235
236 5. Otherwise, if XDG_CONFIG_HOME is set then use
237 $XDG_CONFIG_HOME/ccache/ccache.conf.
238
239 6. Otherwise, use %APPDATA%/ccache/ccache.conf (Windows),
240 $HOME/Library/Preferences/ccache/ccache.conf (macOS) or
241 $HOME/.config/ccache/ccache.conf (other systems).
242
243 Configuration file syntax
244 Configuration files are in a simple “key = value” format, one option
245 per line. Lines starting with a hash sign are comments. Blank lines are
246 ignored, as is whitespace surrounding keys and values. Example:
247
248 # Set maximum cache size to 10 GB:
249 max_size = 10G
250
251 Boolean values
252 Some configuration options are boolean values (i.e. truth values). In a
253 configuration file, such values must be set to the string true or
254 false. For the corresponding environment variables, the semantics are a
255 bit different:
256
257 • A set environment variable means “true” (even if set to the empty
258 string).
259
260 • The following case-insensitive negative values are considered an
261 error (instead of surprising the user): 0, false, disable and no.
262
263 • An unset environment variable means “false”.
264
265 Each boolean environment variable also has a negated form starting with
266 CCACHE_NO. For example, CCACHE_COMPRESS can be set to force compression
267 and CCACHE_NOCOMPRESS can be set to force no compression.
268
269 Configuration options
270 Below is a list of available configuration options. The corresponding
271 environment variable name is indicated in parentheses after each
272 configuration option key.
273
274 absolute_paths_in_stderr (CCACHE_ABSSTDERR)
275 This option specifies whether ccache should rewrite relative paths
276 in the compiler’s standard error output to absolute paths. This can
277 be useful if you use base_dir with a build system (e.g. CMake with
278 the "Unix Makefiles" generator) that executes the compiler in a
279 different working directory, which makes relative paths in compiler
280 errors or warnings incorrect. The default is false.
281
282 base_dir (CCACHE_BASEDIR)
283 This option should be an absolute path to a directory. If set,
284 ccache will rewrite absolute paths into paths relative to the
285 current working directory, but only absolute paths that begin with
286 base_dir. Cache results can then be shared for compilations in
287 different directories even if the project uses absolute paths in
288 the compiler command line. See also the discussion under Compiling
289 in different directories. If set to the empty string (which is the
290 default), no rewriting is done.
291
292 A typical path to use as base_dir is your home directory or another
293 directory that is a parent of your project directories. Don’t use /
294 as the base directory since that will make ccache also rewrite
295 paths to system header files, which typically is contraproductive.
296
297 For example, say that Alice’s current working directory is
298 /home/alice/project1/build and that she compiles like this:
299
300 ccache gcc -I/usr/include/example -I/home/alice/project2/include -c /home/alice/project1/src/example.c
301
302 Here is what ccache will actually execute for different base_dir
303 values:
304
305 # Current working directory: /home/alice/project1/build
306
307 # With base_dir = /:
308 gcc -I../../../../usr/include/example -I../../project2/include -c ../src/example.c
309
310 # With base_dir = /home or /home/alice:
311 gcc -I/usr/include/example -I../../project2/include -c ../src/example.c
312
313 # With base_dir = /home/alice/project1 or /home/alice/project1/src:
314 gcc -I/usr/include/example -I/home/alice/project2/include -c ../src/example.c
315
316 If Bob has put project1 and project2 in /home/bob/stuff and both
317 users have set base_dir to /home or /home/$USER, then Bob will get
318 a cache hit (if they share ccache directory) since the actual
319 command line will be identical to that of Alice:
320
321 # Current working directory: /home/bob/stuff/project1/build
322
323 # With base_dir = /home or /home/bob:
324 gcc -I/usr/include/example -I../../project2/include -c ../src/example.c
325
326 Without base_dir there will be a cache miss since the absolute
327 paths will differ. With base_dir set to / there will be a cache
328 miss since the relative path to /usr/include/example will be
329 different. With base_dir set to /home/bob/stuff/project1 there will
330 a cache miss since the path to project2 will be a different
331 absolute path.
332
333 cache_dir (CCACHE_DIR)
334 This option specifies where ccache will keep its cached compiler
335 outputs. The default is $XDG_CACHE_HOME/ccache if XDG_CACHE_HOME is
336 set, otherwise $HOME/.cache/ccache. Exception: If the legacy
337 directory $HOME/.ccache exists then that directory is the default.
338
339 See also Location of the primary configuration file.
340
341 If you want to use another CCACHE_DIR value temporarily for one
342 ccache invocation you can use the -d/--directory command line
343 option instead.
344
345 compiler (CCACHE_COMPILER or (deprecated) CCACHE_CC)
346 This option can be used to force the name of the compiler to use.
347 If set to the empty string (which is the default), ccache works it
348 out from the command line.
349
350 compiler_check (CCACHE_COMPILERCHECK)
351 By default, ccache includes the modification time (“mtime”) and
352 size of the compiler in the hash to ensure that results retrieved
353 from the cache are accurate. This option can be used to select
354 another strategy. Possible values are:
355
356 content
357 Hash the content of the compiler binary. This makes ccache very
358 slightly slower compared to mtime, but makes it cope better
359 with compiler upgrades during a build bootstrapping process.
360
361 mtime
362 Hash the compiler’s mtime and size, which is fast. This is the
363 default.
364
365 none
366 Don’t hash anything. This may be good for situations where you
367 can safely use the cached results even though the compiler’s
368 mtime or size has changed (e.g. if the compiler is built as
369 part of your build system and the compiler’s source has not
370 changed, or if the compiler only has changes that don’t affect
371 code generation). You should only use none if you know what you
372 are doing.
373
374 string:value
375 Hash value. This can for instance be a compiler revision number
376 or another string that the build system generates to identify
377 the compiler.
378
379 a command string
380 Hash the standard output and standard error output of the
381 specified command. The string will be split on whitespace to
382 find out the command and arguments to run. No other
383 interpretation of the command string will be done, except that
384 the special word %compiler% will be replaced with the path to
385 the compiler. Several commands can be specified with semicolon
386 as separator. Examples:
387
388 %compiler% -v
389
390 %compiler% -dumpmachine; %compiler% -dumpversion
391
392 You should make sure that the specified command is as fast as
393 possible since it will be run once for each ccache invocation.
394
395 Identifying the compiler using a command is useful if you want
396 to avoid cache misses when the compiler has been rebuilt but
397 not changed.
398
399 Another case is when the compiler (as seen by ccache) actually
400 isn’t the real compiler but another compiler wrapper — in that
401 case, the default mtime method will hash the mtime and size of
402 the other compiler wrapper, which means that ccache won’t be
403 able to detect a compiler upgrade. Using a suitable command to
404 identify the compiler is thus safer, but it’s also slower, so
405 you should consider continue using the mtime method in
406 combination with the prefix_command option if possible. See
407 Using ccache with other compiler wrappers.
408
409 compiler_type (CCACHE_COMPILERTYPE)
410 Ccache normally guesses the compiler type based on the compiler
411 name. The compiler_type option lets you force a compiler type. This
412 can be useful if the compiler has a non-standard name but is
413 actually one of the known compiler types. Possible values are:
414
415 auto
416 Guess one of the types below based on the compiler name
417 (following symlinks). This is the default.
418
419 clang
420 Clang-based compiler.
421
422 gcc
423 GCC-based compiler.
424
425 nvcc
426 NVCC (CUDA) compiler.
427
428 other
429 Any compiler other than the known types.
430
431 pump
432 distcc’s "pump" script.
433
434 compression (CCACHE_COMPRESS or CCACHE_NOCOMPRESS, see Boolean values
435 above)
436 If true, ccache will compress data it puts in the cache. However,
437 this option has no effect on how files are retrieved from the
438 cache; compressed and uncompressed results will still be usable
439 regardless of this option. The default is true.
440
441 Compression is done using the Zstandard algorithm. The algorithm is
442 fast enough that there should be little reason to turn off
443 compression to gain performance. One exception is if the cache is
444 located on a compressed file system, in which case the compression
445 performed by ccache of course is redundant.
446
447 Compression will be disabled if file cloning (the file_clone
448 option) or hard linking (the hard_link option) is enabled.
449
450 compression_level (CCACHE_COMPRESSLEVEL)
451 This option determines the level at which ccache will compress
452 object files using the real-time compression algorithm Zstandard.
453 It only has effect if compression is enabled (which it is by
454 default). Zstandard is extremely fast for decompression and very
455 fast for compression for lower compression levels. The default is
456 0.
457
458 Semantics of compression_level:
459
460 > 0
461 A positive value corresponds to normal Zstandard compression
462 levels. Lower levels (e.g. 1) mean faster compression but
463 worse compression ratio. Higher levels (e.g. 19) mean slower
464 compression but better compression ratio. The maximum possible
465 value depends on the libzstd version, but at least up to 19 is
466 available for all versions. Decompression speed is essentially
467 the same for all levels. As a rule of thumb, use level 5 or
468 lower since higher levels may slow down compilations
469 noticeably. Higher levels are however useful when recompressing
470 the cache with command line option -X/--recompress.
471
472 < 0
473 A negative value corresponds to Zstandard’s “ultra-fast”
474 compression levels, which are even faster than level 1 but with
475 less good compression ratios. For instance, level -3
476 corresponds to “--fast=3” for the zstd command line tool. In
477 practice, there is little use for levels lower than -5 or so.
478
479 0 (default)
480 The value 0 means that ccache will choose a suitable level,
481 currently 1.
482
483 See the Zstandard documentation for more information.
484
485 cpp_extension (CCACHE_EXTENSION)
486 This option can be used to force a certain extension for the
487 intermediate preprocessed file. The default is to automatically
488 determine the extension to use for intermediate preprocessor files
489 based on the type of file being compiled, but that sometimes
490 doesn’t work. For example, when using the “aCC” compiler on HP-UX,
491 set the cpp extension to i.
492
493 debug (CCACHE_DEBUG or CCACHE_NODEBUG, see Boolean values above)
494 If true, enable the debug mode. The debug mode creates per-object
495 debug files that are helpful when debugging unexpected cache
496 misses. Note however that ccache performance will be reduced
497 slightly. See Cache debugging for more information. The default is
498 false.
499
500 debug_dir (CCACHE_DEBUGDIR)
501 Specifies where to write per-object debug files if the debug mode
502 is enabled. If set to the empty string, the files will be written
503 next to the object file. If set to a directory, the debug files
504 will be written with full absolute paths in that directory,
505 creating it if needed. The default is the empty string.
506
507 For example, if debug_dir is set to /example, the current working
508 directory is /home/user and the object file is build/output.o then
509 the debug log will be written to
510 /example/home/user/build/output.o.ccache-log. See also Cache
511 debugging.
512
513 depend_mode (CCACHE_DEPEND or CCACHE_NODEPEND, see Boolean values
514 above)
515 If true, the depend mode will be used. The default is false. See
516 The depend mode.
517
518 direct_mode (CCACHE_DIRECT or CCACHE_NODIRECT, see Boolean values
519 above)
520 If true, the direct mode will be used. The default is true. See The
521 direct mode.
522
523 disable (CCACHE_DISABLE or CCACHE_NODISABLE, see Boolean values above)
524 When true, ccache will just call the real compiler, bypassing the
525 cache completely. The default is false.
526
527 extra_files_to_hash (CCACHE_EXTRAFILES)
528 This option is a list of paths to files that ccache will include in
529 the the hash sum that identifies the build. The list separator is
530 semicolon on Windows systems and colon on other systems.
531
532 file_clone (CCACHE_FILECLONE or CCACHE_NOFILECLONE, see Boolean values
533 above)
534 If true, ccache will attempt to use file cloning (also known as
535 “copy on write”, “CoW” or “reflinks”) to store and fetch cached
536 compiler results. file_clone has priority over hard_link. The
537 default is false.
538
539 Files stored by cloning cannot be compressed, so the cache size
540 will likely be significantly larger if this option is enabled.
541 However, performance may be improved depending on the use case.
542
543 Unlike the hard_link option, file_clone is completely safe to use,
544 but not all file systems support the feature. For such file
545 systems, ccache will fall back to use plain copying (or hard links
546 if hard_link is enabled).
547
548 hard_link (CCACHE_HARDLINK or CCACHE_NOHARDLINK, see Boolean values
549 above)
550 If true, ccache will attempt to use hard links to store and fetch
551 cached object files. The default is false.
552
553 Files stored via hard links cannot be compressed, so the cache size
554 will likely be significantly larger if this option is enabled.
555 However, performance may be improved depending on the use case.
556
557 Warning
558 Do not enable this option unless you are aware of these
559 caveats:
560
561 • If the resulting file is modified, the file in the cache will
562 also be modified since they share content, which corrupts the
563 cache entry. As of version 4.0, ccache makes stored and fetched
564 object files read-only as a safety measure guard. Furthermore,
565 a simple integrity check is made for cached object files by
566 verifying that their sizes are correct. This means that
567 mistakes like strip file.o or echo >file.o will be detected
568 even if the object file is made writeable, but a modification
569 that doesn’t change the file size will not.
570
571 • Programs that don’t expect that files from two different
572 identical compilations are hard links to each other can fail.
573
574 • Programs that rely on modification times (like “make”) can be
575 confused if several users (or one user with several build
576 trees) use the same cache directory. The reason for this is
577 that the object files share i-nodes and therefore modification
578 times. If file.o is in build tree A (hard-linked from the
579 cache) and file.o then is produced by ccache in build tree B by
580 hard-linking from the cache, the modification timestamp will be
581 updated for file.o in build tree A as well. This can retrigger
582 relinking in build tree A even though nothing really has
583 changed.
584
585 hash_dir (CCACHE_HASHDIR or CCACHE_NOHASHDIR, see Boolean values above)
586 If true (which is the default), ccache will include the current
587 working directory (CWD) in the hash that is used to distinguish two
588 compilations when generating debug info (compiler option -g with
589 variations). Exception: The CWD will not be included in the hash if
590 base_dir is set (and matches the CWD) and the compiler option
591 -fdebug-prefix-map is used. See also the discussion under Compiling
592 in different directories.
593
594 The reason for including the CWD in the hash by default is to
595 prevent a problem with the storage of the current working directory
596 in the debug info of an object file, which can lead ccache to
597 return a cached object file that has the working directory in the
598 debug info set incorrectly.
599
600 You can disable this option to get cache hits when compiling the
601 same source code in different directories if you don’t mind that
602 CWD in the debug info might be incorrect.
603
604 ignore_headers_in_manifest (CCACHE_IGNOREHEADERS)
605 This option is a list of paths to files (or directories with
606 headers) that ccache will not include in the manifest list that
607 makes up the direct mode. Note that this can cause stale cache hits
608 if those headers do indeed change. The list separator is semicolon
609 on Windows systems and colon on other systems.
610
611 ignore_options (CCACHE_IGNOREOPTIONS)
612 This option is a space-delimited list of compiler options that
613 ccache will exclude from the hash. Excluding a compiler option from
614 the hash can be useful when you know it doesn’t affect the result
615 (but ccache doesn’t know that), or when it does and you don’t care.
616 If a compiler option in the list is suffixed with an asterisk (*)
617 it will be matched as a prefix. For example, -fmessage-length=*
618 will match both -fmessage-length=20 and -fmessage-length=70.
619
620 inode_cache (CCACHE_INODECACHE or CCACHE_NOINODECACHE, see Boolean
621 values above)
622 If true, enables caching of source file hashes based on device,
623 inode and timestamps. This will reduce the time spent on hashing
624 included files as the result can be resused between compilations.
625
626 The feature is still experimental and thus off by default. It is
627 currently not available on Windows.
628
629 The feature requires temporary_dir to be located on a local
630 filesystem.
631
632 keep_comments_cpp (CCACHE_COMMENTS or CCACHE_NOCOMMENTS, see Boolean
633 values above)
634 If true, ccache will not discard the comments before hashing
635 preprocessor output. This can be used to check documentation with
636 -Wdocumentation.
637
638 limit_multiple (CCACHE_LIMIT_MULTIPLE)
639 Sets the limit when cleaning up. Files are deleted (in LRU order)
640 until the levels are below the limit. The default is 0.8 (= 80%).
641 See Automatic cleanup for more information.
642
643 log_file (CCACHE_LOGFILE)
644 If set to a file path, ccache will write information on what it is
645 doing to the specified file. This is useful for tracking down
646 problems.
647
648 If set to syslog, ccache will log using syslog() instead of to a
649 file. If you use rsyslogd, you can add something like this to
650 /etc/rsyslog.conf or a file in /etc/rsyslog.d:
651
652 # log ccache to file
653 :programname, isequal, "ccache" /var/log/ccache
654 # remove from syslog
655 & ~
656
657 max_files (CCACHE_MAXFILES)
658 This option specifies the maximum number of files to keep in the
659 cache. Use 0 for no limit (which is the default). See also Cache
660 size management.
661
662 max_size (CCACHE_MAXSIZE)
663 This option specifies the maximum size of the cache. Use 0 for no
664 limit. The default value is 5G. Available suffixes: k, M, G, T
665 (decimal) and Ki, Mi, Gi, Ti (binary). The default suffix is G. See
666 also Cache size management.
667
668 path (CCACHE_PATH)
669 If set, ccache will search directories in this list when looking
670 for the real compiler. The list separator is semicolon on Windows
671 systems and colon on other systems. If not set, ccache will look
672 for the first executable matching the compiler name in the normal
673 PATH that isn’t a symbolic link to ccache itself.
674
675 pch_external_checksum (CCACHE_PCH_EXTSUM or CCACHE_NOPCH_EXTSUM, see
676 Boolean values above)
677 When this option is set, and ccache finds a precompiled header
678 file, ccache will look for a file with the extension “.sum” added
679 (e.g. “pre.h.gch.sum”), and if found, it will hash this file
680 instead of the precompiled header itself to work around the
681 performance penalty of hashing very large files.
682
683 prefix_command (CCACHE_PREFIX)
684 This option adds a list of prefixes (separated by space) to the
685 command line that ccache uses when invoking the compiler. See also
686 Using ccache with other compiler wrappers.
687
688 prefix_command_cpp (CCACHE_PREFIX_CPP)
689 This option adds a list of prefixes (separated by space) to the
690 command line that ccache uses when invoking the preprocessor.
691
692 read_only (CCACHE_READONLY or CCACHE_NOREADONLY, see Boolean values
693 above)
694 If true, ccache will attempt to use existing cached results, but it
695 will not add new results to the cache. Statistics counters will
696 still be updated, though, unless the stats option is set to false.
697
698 If you are using this because your ccache directory is read-only,
699 you need to set temporary_dir since ccache will fail to create
700 temporary files otherwise. You may also want to set stats to false
701 make ccache not even try to update stats files.
702
703 read_only_direct (CCACHE_READONLY_DIRECT or CCACHE_NOREADONLY_DIRECT,
704 see Boolean values above)
705 Just like read_only except that ccache will only try to retrieve
706 results from the cache using the direct mode, not the preprocessor
707 mode. See documentation for read_only regarding using a read-only
708 ccache directory.
709
710 recache (CCACHE_RECACHE or CCACHE_NORECACHE, see Boolean values above)
711 If true, ccache will not use any previously stored result. New
712 results will still be cached, possibly overwriting any pre-existing
713 results.
714
715 run_second_cpp (CCACHE_CPP2 or CCACHE_NOCPP2, see Boolean values above)
716 If true, ccache will first run the preprocessor to preprocess the
717 source code (see The preprocessor mode) and then on a cache miss
718 run the compiler on the source code to get hold of the object file.
719 This is the default.
720
721 If false, ccache will first run preprocessor to preprocess the
722 source code and then on a cache miss run the compiler on the
723 preprocessed source code instead of the original source code. This
724 makes cache misses slightly faster since the source code only has
725 to be preprocessed once. The downside is that some compilers won’t
726 produce the same result (for instance diagnostics warnings) when
727 compiling preprocessed source code.
728
729 A solution to the above mentioned downside is to set run_second_cpp
730 to false and pass -fdirectives-only (for GCC) or -frewrite-includes
731 (for Clang) to the compiler. This will cause the compiler to leave
732 the macros and other preprocessor information, and only process the
733 #include directives. When run in this way, the preprocessor
734 arguments will be passed to the compiler since it still has to do
735 some preprocessing (like macros).
736
737 sloppiness (CCACHE_SLOPPINESS)
738 By default, ccache tries to give as few false cache hits as
739 possible. However, in certain situations it’s possible that you
740 know things that ccache can’t take for granted. This option makes
741 it possible to tell ccache to relax some checks in order to
742 increase the hit rate. The value should be a comma-separated string
743 with one or several of the following values:
744
745 clang_index_store
746 Ignore the Clang compiler option -index-store-path and its
747 argument when computing the manifest hash. This is useful if
748 you use Xcode, which uses an index store path derived from the
749 local project path. Note that the index store won’t be updated
750 correctly on cache hits if you enable this sloppiness.
751
752 file_stat_matches
753 Ccache normally examines a file’s contents to determine whether
754 it matches the cached version. With this sloppiness set, ccache
755 will consider a file as matching its cached version if the
756 mtimes and ctimes match.
757
758 file_stat_matches_ctime
759 Ignore ctimes when file_stat_matches is enabled. This can be
760 useful when backdating files' mtimes in a controlled way.
761
762 include_file_ctime
763 By default, ccache will not cache a file if it includes a
764 header whose ctime is too new. This sloppiness disables that
765 check. See also Handling of newly created header files.
766
767 include_file_mtime
768 By default, ccache will not cache a file if it includes a
769 header whose mtime is too new. This sloppiness disables that
770 check. See also Handling of newly created header files.
771
772 locale
773 Ccache includes the environment variables LANG, LC_ALL,
774 LC_CTYPE and LC_MESSAGES in the hash by default since they may
775 affect localization of compiler warning messages. Set this
776 sloppiness to tell ccache not to do that.
777
778 pch_defines
779 Be sloppy about #defines when precompiling a header file. See
780 Precompiled headers for more information.
781
782 modules
783 By default, ccache will not cache compilations if -fmodules is
784 used since it cannot hash the state of compiler’s internal
785 representation of relevant modules. This sloppiness allows
786 caching in such a case. See C++ modules for more information.
787
788 system_headers
789 By default, ccache will also include all system headers in the
790 manifest. With this sloppiness set, ccache will only include
791 system headers in the hash but not add the system header files
792 to the list of include files.
793
794 time_macros
795 Ignore __DATE__, __TIME__ and __TIMESTAMP__ being present in
796 the source code.
797
798 See the discussion under Troubleshooting for more information.
799
800 stats (CCACHE_STATS or CCACHE_NOSTATS, see Boolean values above)
801 If true, ccache will update the statistics counters on each
802 compilation. The default is true.
803
804 temporary_dir (CCACHE_TEMPDIR)
805 This option specifies where ccache will put temporary files. The
806 default is /run/user/<UID>/ccache-tmp if /run/user/<UID> exists,
807 otherwise <cache_dir>/tmp.
808
809 Note
810 In previous versions of ccache, CCACHE_TEMPDIR had to be on the
811 same filesystem as the CCACHE_DIR path, but this requirement
812 has been relaxed.)
813
814 umask (CCACHE_UMASK)
815 This option specifies the umask for files and directories in the
816 cache directory. This is mostly useful when you wish to share your
817 cache with other users.
818
820 By default, ccache has a 5 GB limit on the total size of files in the
821 cache and no limit on the number of files. You can set different limits
822 using the command line options -M/--max-size and -F/--max-files. Use
823 ccache -s/--show-stats to see the cache size and the currently
824 configured limits (in addition to other various statistics).
825
826 Cleanup can be triggered in two different ways: automatic and manual.
827
828 Automatic cleanup
829 Ccache maintains counters for various statistics about the cache,
830 including the size and number of all cached files. In order to improve
831 performance and reduce issues with concurrent ccache invocations, there
832 is one statistics file for each of the sixteen subdirectories in the
833 cache.
834
835 After a new compilation result has been written to the cache, ccache
836 will update the size and file number statistics for the subdirectory
837 (one of sixteen) to which the result was written. Then, if the size
838 counter for said subdirectory is greater than max_size / 16 or the file
839 number counter is greater than max_files / 16, automatic cleanup is
840 triggered.
841
842 When automatic cleanup is triggered for a subdirectory in the cache,
843 ccache will:
844
845 1. Count all files in the subdirectory and compute their aggregated
846 size.
847
848 2. Remove files in LRU (least recently used) order until the size is
849 at most limit_multiple * max_size / 16 and the number of files is
850 at most limit_multiple * max_files / 16, where limit_multiple,
851 max_size and max_files are configuration options.
852
853 3. Set the size and file number counters to match the files that were
854 kept.
855
856 The reason for removing more files than just those needed to not exceed
857 the max limits is that a cleanup is a fairly slow operation, so it
858 would not be a good idea to trigger it often, like after each cache
859 miss.
860
861 Manual cleanup
862 You can run ccache -c/--cleanup to force cleanup of the whole cache,
863 i.e. all of the sixteen subdirectories. This will recalculate the
864 statistics counters and make sure that the configuration options
865 max_size and max_files are not exceeded. Note that limit_multiple is
866 not taken into account for manual cleanup.
867
869 Ccache will by default compress all data it puts into the cache using
870 the compression algorithm Zstandard (zstd) using compression level 1.
871 The algorithm is fast enough that there should be little reason to turn
872 off compression to gain performance. One exception is if the cache is
873 located on a compressed file system, in which case the compression
874 performed by ccache of course is redundant. See the documentation for
875 the configuration options compression and compression_level for more
876 information.
877
878 You can use the command line option -x/--show-compression to print
879 information related to compression. Example:
880
881 Total data: 14.8 GB (16.0 GB disk blocks)
882 Compressed data: 11.3 GB (30.6% of original size)
883 - Original data: 36.9 GB
884 - Compression ratio: 3.267 x (69.4% space savings)
885 Incompressible data: 3.5 GB
886
887 Notes:
888
889 • The “disk blocks” size is the cache size when taking disk block
890 size into account. This value should match the “cache size” value
891 from “ccache --show-stats”. The other size numbers refer to actual
892 content sizes.
893
894 • “Compressed data” refers to result and manifest files stored in the
895 cache.
896
897 • “Incompressible data” refers to files that are always stored
898 uncompressed (triggered by enabling file_clone or hard_link) or
899 unknown files (for instance files created by older ccache
900 versions).
901
902 • The compression ratio is affected by compression_level.
903
904 The cache data can also be recompressed to another compression level
905 (or made uncompressed) with the command line option -X/--recompress. If
906 you choose to disable compression by default or to use a low
907 compression level, you can (re)compress newly cached data with a higher
908 compression level after the build or at another time when there are
909 more CPU cycles available, for instance every night. Full recompression
910 potentially takes a lot of time, but only files that are currently
911 compressed with a different level than the target level will be
912 recompressed.
913
915 ccache -s/--show-stats can show the following statistics:
916
917 ┌───────────────────────────┬────────────────────────────┐
918 │Name │ Description │
919 ├───────────────────────────┼────────────────────────────┤
920 │ │ │
921 │autoconf compile/link │ Uncachable compilation or │
922 │ │ linking by an autoconf │
923 │ │ test. │
924 ├───────────────────────────┼────────────────────────────┤
925 │ │ │
926 │bad compiler arguments │ Malformed compiler │
927 │ │ argument, e.g. missing a │
928 │ │ value for a compiler │
929 │ │ option that requires an │
930 │ │ argument or failure to │
931 │ │ read a file specified by a │
932 │ │ compiler option argument. │
933 ├───────────────────────────┼────────────────────────────┤
934 │ │ │
935 │cache file missing │ A file was unexpectedly │
936 │ │ missing from the cache. │
937 │ │ This only happens in rare │
938 │ │ situations, e.g. if one │
939 │ │ ccache instance is about │
940 │ │ to get a file from the │
941 │ │ cache while another │
942 │ │ instance removed the file │
943 │ │ as part of cache cleanup. │
944 ├───────────────────────────┼────────────────────────────┤
945 │ │ │
946 │cache hit (direct) │ A result was successfully │
947 │ │ found using the direct │
948 │ │ mode. │
949 ├───────────────────────────┼────────────────────────────┤
950 │ │ │
951 │cache hit (preprocessed) │ A result was successfully │
952 │ │ found using the │
953 │ │ preprocessor mode. │
954 ├───────────────────────────┼────────────────────────────┤
955 │ │ │
956 │cache miss │ No result was found. │
957 ├───────────────────────────┼────────────────────────────┤
958 │ │ │
959 │cache size │ Current size of the cache. │
960 ├───────────────────────────┼────────────────────────────┤
961 │ │ │
962 │called for link │ The compiler was called │
963 │ │ for linking, not │
964 │ │ compiling. Ccache only │
965 │ │ supports compilation of a │
966 │ │ single file, i.e. calling │
967 │ │ the compiler with the -c │
968 │ │ option to produce a single │
969 │ │ object file from a single │
970 │ │ source file. │
971 ├───────────────────────────┼────────────────────────────┤
972 │ │ │
973 │called for preprocessing │ The compiler was called │
974 │ │ for preprocessing, not │
975 │ │ compiling. │
976 ├───────────────────────────┼────────────────────────────┤
977 │ │ │
978 │can’t use precompiled │ Preconditions for using │
979 │header │ precompiled headers were │
980 │ │ not fulfilled. │
981 ├───────────────────────────┼────────────────────────────┤
982 │ │ │
983 │can’t use modules │ Preconditions for using │
984 │ │ C++ modules were not │
985 │ │ fulfilled. │
986 ├───────────────────────────┼────────────────────────────┤
987 │ │ │
988 │ccache internal error │ Unexpected failure, e.g. │
989 │ │ due to problems │
990 │ │ reading/writing the cache. │
991 ├───────────────────────────┼────────────────────────────┤
992 │ │ │
993 │cleanups performed │ Number of cleanups │
994 │ │ performed, either │
995 │ │ implicitly due to the │
996 │ │ cache size limit being │
997 │ │ reached or due to explicit │
998 │ │ ccache -c/--cleanup calls. │
999 ├───────────────────────────┼────────────────────────────┤
1000 │ │ │
1001 │compile failed │ The compilation failed. No │
1002 │ │ result stored in the │
1003 │ │ cache. │
1004 ├───────────────────────────┼────────────────────────────┤
1005 │ │ │
1006 │compiler check failed │ A compiler check program │
1007 │ │ specified by │
1008 │ │ compiler_check │
1009 │ │ (CCACHE_COMPILERCHECK) │
1010 │ │ failed. │
1011 ├───────────────────────────┼────────────────────────────┤
1012 │ │ │
1013 │compiler produced empty │ The compiler’s output file │
1014 │output │ (typically an object file) │
1015 │ │ was empty after │
1016 │ │ compilation. │
1017 ├───────────────────────────┼────────────────────────────┤
1018 │ │ │
1019 │compiler produced no │ The compiler’s output file │
1020 │output │ (typically an object file) │
1021 │ │ was missing after │
1022 │ │ compilation. │
1023 ├───────────────────────────┼────────────────────────────┤
1024 │ │ │
1025 │compiler produced stdout │ The compiler wrote data to │
1026 │ │ standard output. This is │
1027 │ │ something that compilers │
1028 │ │ normally never do, so │
1029 │ │ ccache is not designed to │
1030 │ │ store such output in the │
1031 │ │ cache. │
1032 ├───────────────────────────┼────────────────────────────┤
1033 │ │ │
1034 │couldn’t find the compiler │ The compiler to execute │
1035 │ │ could not be found. │
1036 ├───────────────────────────┼────────────────────────────┤
1037 │ │ │
1038 │error hashing extra file │ Failure reading a file │
1039 │ │ specified by │
1040 │ │ extra_files_to_hash │
1041 │ │ (CCACHE_EXTRAFILES). │
1042 ├───────────────────────────┼────────────────────────────┤
1043 │ │ │
1044 │files in cache │ Current number of files in │
1045 │ │ the cache. │
1046 ├───────────────────────────┼────────────────────────────┤
1047 │ │ │
1048 │multiple source files │ The compiler was called to │
1049 │ │ compile multiple source │
1050 │ │ files in one go. This is │
1051 │ │ not supported by ccache. │
1052 ├───────────────────────────┼────────────────────────────┤
1053 │ │ │
1054 │no input file │ No input file was │
1055 │ │ specified to the compiler. │
1056 ├───────────────────────────┼────────────────────────────┤
1057 │ │ │
1058 │output to a non-regular │ The output path specified │
1059 │file │ with -o is not a file │
1060 │ │ (e.g. a directory or a │
1061 │ │ device node). │
1062 ├───────────────────────────┼────────────────────────────┤
1063 │ │ │
1064 │output to stdout │ The compiler was │
1065 │ │ instructed to write its │
1066 │ │ output to standard output │
1067 │ │ using -o -. This is not │
1068 │ │ supported by ccache. │
1069 ├───────────────────────────┼────────────────────────────┤
1070 │ │ │
1071 │preprocessor error │ Preprocessing the source │
1072 │ │ code using the compiler’s │
1073 │ │ -E option failed. │
1074 ├───────────────────────────┼────────────────────────────┤
1075 │ │ │
1076 │stats updated │ When statistics were │
1077 │ │ updated the last time. │
1078 ├───────────────────────────┼────────────────────────────┤
1079 │ │ │
1080 │stats zeroed │ When ccache -z was called │
1081 │ │ the last time. │
1082 ├───────────────────────────┼────────────────────────────┤
1083 │ │ │
1084 │unsupported code directive │ Code like the assembler │
1085 │ │ .incbin directive was │
1086 │ │ found. This is not │
1087 │ │ supported by ccache. │
1088 ├───────────────────────────┼────────────────────────────┤
1089 │ │ │
1090 │unsupported compiler │ A compiler option not │
1091 │option │ supported by ccache was │
1092 │ │ found. │
1093 ├───────────────────────────┼────────────────────────────┤
1094 │ │ │
1095 │unsupported source │ A source language e.g. │
1096 │language │ specified with -x was │
1097 │ │ unsupported by ccache. │
1098 └───────────────────────────┴────────────────────────────┘
1099
1101 The basic idea is to detect when you are compiling exactly the same
1102 code a second time and reuse the previously produced output. The
1103 detection is done by hashing different kinds of information that should
1104 be unique for the compilation and then using the hash sum to identify
1105 the cached output. Ccache uses BLAKE3, a very fast cryptographic hash
1106 algorithm, for the hashing. On a cache hit, ccache is able to supply
1107 all of the correct compiler outputs (including all warnings, dependency
1108 file, etc) from the cache. Data stored in the cache is checksummed with
1109 XXH3, an extremely fast non-cryptographic algorithm, to detect
1110 corruption.
1111
1112 Ccache has two ways of gathering information used to look up results in
1113 the cache:
1114
1115 • the preprocessor mode, where ccache runs the preprocessor on the
1116 source code and hashes the result
1117
1118 • the direct mode, where ccache hashes the source code and include
1119 files directly
1120
1121 The direct mode is generally faster since running the preprocessor has
1122 some overhead.
1123
1124 If no previous result is detected (i.e., there is a cache miss) using
1125 the direct mode, ccache will fall back to the preprocessor mode unless
1126 the depend mode is enabled. In the depend mode, ccache never runs the
1127 preprocessor, not even on cache misses. Read more in The depend mode
1128 below.
1129
1130 Common hashed information
1131 The following information is always included in the hash:
1132
1133 • the extension used by the compiler for a file with preprocessor
1134 output (normally .i for C code and .ii for C++ code)
1135
1136 • the compiler’s size and modification time (or other
1137 compiler-specific information specified by compiler_check)
1138
1139 • the name of the compiler
1140
1141 • the current directory (if hash_dir is enabled)
1142
1143 • contents of files specified by extra_files_to_hash (if any)
1144
1145 The preprocessor mode
1146 In the preprocessor mode, the hash is formed of the common information
1147 and:
1148
1149 • the preprocessor output from running the compiler with -E
1150
1151 • the command line options except those that affect include files
1152 (-I, -include, -D, etc; the theory is that these command line
1153 options will change the preprocessor output if they have any effect
1154 at all)
1155
1156 • any standard error output generated by the preprocessor
1157
1158 Based on the hash, the cached compilation result can be looked up
1159 directly in the cache.
1160
1161 The direct mode
1162 In the direct mode, the hash is formed of the common information and:
1163
1164 • the input source file
1165
1166 • the compiler options
1167
1168 Based on the hash, a data structure called “manifest” is looked up in
1169 the cache. The manifest contains:
1170
1171 • references to cached compilation results (object file, dependency
1172 file, etc) that were produced by previous compilations that matched
1173 the hash
1174
1175 • paths to the include files that were read at the time the
1176 compilation results were stored in the cache
1177
1178 • hash sums of the include files at the time the compilation results
1179 were stored in the cache
1180
1181 The current contents of the include files are then hashed and compared
1182 to the information in the manifest. If there is a match, ccache knows
1183 the result of the compilation. If there is no match, ccache falls back
1184 to running the preprocessor. The output from the preprocessor is parsed
1185 to find the include files that were read. The paths and hash sums of
1186 those include files are then stored in the manifest along with
1187 information about the produced compilation result.
1188
1189 There is a catch with the direct mode: header files that were used by
1190 the compiler are recorded, but header files that were not used, but
1191 would have been used if they existed, are not. So, when ccache checks
1192 if a result can be taken from the cache, it currently can’t check if
1193 the existence of a new header file should invalidate the result. In
1194 practice, the direct mode is safe to use in the absolute majority of
1195 cases.
1196
1197 The direct mode will be disabled if any of the following holds:
1198
1199 • direct_mode is false
1200
1201 • a modification time of one of the include files is too new (needed
1202 to avoid a race condition)
1203
1204 • a compiler option not supported by the direct mode is used:
1205
1206 • a -Wp,X compiler option other than -Wp,-MD,path, -Wp,-MMD,path
1207 and -Wp,-D_define_
1208
1209 • -Xpreprocessor
1210
1211 • the string __TIME__ is present in the source code
1212
1213 The depend mode
1214 If the depend mode is enabled, ccache will not use the preprocessor at
1215 all. The hash used to identify results in the cache will be based on
1216 the direct mode hash described above plus information about include
1217 files read from the dependency file generated by the compiler with -MD
1218 or -MMD.
1219
1220 Advantages:
1221
1222 • The ccache overhead of a cache miss will be much smaller.
1223
1224 • Not running the preprocessor at all can be good if compilation is
1225 performed remotely, for instance when using distcc or similar;
1226 ccache then won’t make potentially costly preprocessor calls on the
1227 local machine.
1228
1229 Disadvantages:
1230
1231 • The cache hit rate will likely be lower since any change to
1232 compiler options or source code will make the hash different.
1233 Compare this with the default setup where ccache will fall back to
1234 the preprocessor mode, which is tolerant to some types of changes
1235 of compiler options and source code changes.
1236
1237 • If -MD is used, the manifest entries will include system header
1238 files as well, thus slowing down cache hits slightly, just as using
1239 -MD slows down make.
1240
1241 • If -MMD is used, the manifest entries will not include system
1242 header files, which means ccache will ignore changes in them.
1243
1244 The depend mode will be disabled if any of the following holds:
1245
1246 • depend_mode is false.
1247
1248 • run_second_cpp is false.
1249
1250 • The compiler is not generating dependencies using -MD or -MMD.
1251
1253 If modification time (mtime) or status change time (ctime) of one of
1254 the include files is the same second as the time compilation is being
1255 done, ccache disables the direct mode (or, in the case of a precompiled
1256 header, disables caching completely). This done as a safety measure to
1257 avoid a race condition (see below).
1258
1259 To be able to use a newly created header files in direct mode (or use a
1260 newly precompiled header), either:
1261
1262 • create the include file earlier in the build process, or
1263
1264 • set sloppiness to include_file_ctime,include_file_mtime if you are
1265 willing to take the risk, for instance if you know that your build
1266 system is robust enough not to trigger the race condition.
1267
1268 For reference, the race condition mentioned above consists of these
1269 events:
1270
1271 1. The preprocessor is run.
1272
1273 2. An include file is modified by someone.
1274
1275 3. The new include file is hashed by ccache.
1276
1277 4. The real compiler is run on the preprocessor’s output, which
1278 contains data from the old header file.
1279
1280 5. The wrong object file is stored in the cache.
1281
1283 To find out what information ccache actually is hashing, you can enable
1284 the debug mode via the configuration option debug or by setting
1285 CCACHE_DEBUG in the environment. This can be useful if you are
1286 investigating why you don’t get cache hits. Note that performance will
1287 be reduced slightly.
1288
1289 When the debug mode is enabled, ccache will create up to five
1290 additional files next to the object file:
1291
1292 ┌───────────────────────────────┬───────────────────────────┐
1293 │Filename │ Description │
1294 ├───────────────────────────────┼───────────────────────────┤
1295 │ │ │
1296 │<objectfile>.ccache-input-c │ Binary input hashed by │
1297 │ │ both the direct mode and │
1298 │ │ the preprocessor mode. │
1299 ├───────────────────────────────┼───────────────────────────┤
1300 │ │ │
1301 │<objectfile>.ccache-input-d │ Binary input only hashed │
1302 │ │ by the direct mode. │
1303 ├───────────────────────────────┼───────────────────────────┤
1304 │ │ │
1305 │<objectfile>.ccache-input-p │ Binary input only hashed │
1306 │ │ by the preprocessor mode. │
1307 ├───────────────────────────────┼───────────────────────────┤
1308 │ │ │
1309 │<objectfile>.ccache-input-text │ Human-readable combined │
1310 │ │ diffable text version of │
1311 │ │ the three files above. │
1312 ├───────────────────────────────┼───────────────────────────┤
1313 │ │ │
1314 │<objectfile>.ccache-log │ Log for this object file. │
1315 └───────────────────────────────┴───────────────────────────┘
1316
1317 If config_dir (environment variable CCACHE_DEBUGDIR) is set, the files
1318 above will be written to that directory with full absolute paths
1319 instead of next to the object file.
1320
1321 In the direct mode, ccache uses the 160 bit BLAKE3 hash of the
1322 ccache-input-c + ccache-input-d data (where + means concatenation),
1323 while the ccache-input-c + ccache-input-p data is used in the
1324 preprocessor mode.
1325
1326 The ccache-input-text file is a combined text version of the three
1327 binary input files. It has three sections (“COMMON”, “DIRECT MODE” and
1328 “PREPROCESSOR MODE”), which is turn contain annotations that say what
1329 kind of data comes next.
1330
1331 To debug why you don’t get an expected cache hit for an object file,
1332 you can do something like this:
1333
1334 1. Build with debug mode enabled.
1335
1336 2. Save the <objectfile>.ccache-* files.
1337
1338 3. Build again with debug mode enabled.
1339
1340 4. Compare <objectfile>.ccache-input-text for the two builds. This
1341 together with the <objectfile>.ccache-log files should give you
1342 some clues about what is happening.
1343
1345 Some information included in the hash that identifies a unique
1346 compilation can contain absolute paths:
1347
1348 • The preprocessed source code may contain absolute paths to include
1349 files if the compiler option -g is used or if absolute paths are
1350 given to -I and similar compiler options.
1351
1352 • Paths specified by compiler options (such as -I, -MF, etc) on the
1353 command line may be absolute.
1354
1355 • The source code file path may be absolute, and that path may
1356 substituted for __FILE__ macros in the source code or included in
1357 warnings emitted to standard error by the preprocessor.
1358
1359 This means that if you compile the same code in different locations,
1360 you can’t share compilation results between the different build
1361 directories since you get cache misses because of the absolute build
1362 directory paths that are part of the hash.
1363
1364 Here’s what can be done to enable cache hits between different build
1365 directories:
1366
1367 • If you build with -g (or similar) to add debug information to the
1368 object file, you must either:
1369
1370 • use the compiler option -fdebug-prefix-map=old=new for
1371 relocating debug info to a common prefix (e.g.
1372 -fdebug-prefix-map=$PWD=.); or
1373
1374 • set hash_dir = false.
1375
1376 • If you use absolute paths anywhere on the command line (e.g. the
1377 source code file path or an argument to compiler options like -I
1378 and -MF), you must set base_dir to an absolute path to a “base
1379 directory”. Ccache will then rewrite absolute paths under that
1380 directory to relative before computing the hash.
1381
1383 Ccache has support for GCC’s precompiled headers. However, you have to
1384 do some things to make it work properly:
1385
1386 • You must set sloppiness to pch_defines,time_macros. The reason is
1387 that ccache can’t tell whether __TIME__, __DATE__ or __TIMESTAMP__
1388 is used when using a precompiled header. Further, it can’t detect
1389 changes in #defines in the source code because of how preprocessing
1390 works in combination with precompiled headers.
1391
1392 • You may also want to include include_file_mtime,include_file_ctime
1393 in sloppiness. See Handling of newly created header files.
1394
1395 • You must either:
1396
1397 • use the compiler option -include to include the precompiled
1398 header (i.e., don’t use #include in the source code to include
1399 the header; the filename itself must be sufficient to find the
1400 header, i.e. -I paths are not searched); or
1401
1402 • (for the Clang compiler) use the compiler option -include-pch
1403 to include the PCH file generated from the precompiled header;
1404 or
1405
1406 • (for the GCC compiler) add the compiler option -fpch-preprocess
1407 when compiling.
1408
1409 If you don’t do this, either the non-precompiled version of the
1410 header file will be used (if available) or ccache will fall back to
1411 running the real compiler and increase the statistics counter
1412 “preprocessor error” (if the non-precompiled header file is not
1413 available).
1414
1416 Ccache has support for Clang’s -fmodules option. In practice ccache
1417 only additionally hashes module.modulemap files; it does not know how
1418 Clang handles its cached binary form of modules so those are ignored.
1419 This should not matter in practice: as long as everything else
1420 (including module.modulemap files) is the same the cached result should
1421 work. Still, you must set sloppiness to modules to allow caching.
1422
1423 You must use both direct mode and depend mode. When using the
1424 preprocessor mode Clang does not provide enough information to allow
1425 hashing of module.modulemap files.
1426
1428 A group of developers can increase the cache hit rate by sharing a
1429 cache directory. To share a cache without unpleasant side effects, the
1430 following conditions should to be met:
1431
1432 • Use the same cache directory.
1433
1434 • Make sure that the configuration option hard_link is false (which
1435 is the default).
1436
1437 • Make sure that all users are in the same group.
1438
1439 • Set the configuration option umask to 002. This ensures that cached
1440 files are accessible to everyone in the group.
1441
1442 • Make sure that all users have write permission in the entire cache
1443 directory (and that you trust all users of the shared cache).
1444
1445 • Make sure that the setgid bit is set on all directories in the
1446 cache. This tells the filesystem to inherit group ownership for new
1447 directories. The following command might be useful for this:
1448
1449 find $CCACHE_DIR -type d | xargs chmod g+s
1450
1451 The reason to avoid the hard link mode is that the hard links cause
1452 unwanted side effects, as all links to a cached file share the file’s
1453 modification timestamp. This results in false dependencies to be
1454 triggered by timestamp-based build systems whenever another user links
1455 to an existing file. Typically, users will see that their libraries and
1456 binaries are relinked without reason.
1457
1458 You may also want to make sure that a base directory is set
1459 appropriately, as discussed in a previous section.
1460
1462 It is possible to put the cache directory on an NFS filesystem (or
1463 similar filesystems), but keep in mind that:
1464
1465 • Having the cache on NFS may slow down compilation. Make sure to do
1466 some benchmarking to see if it’s worth it.
1467
1468 • Ccache hasn’t been tested very thoroughly on NFS.
1469
1470 A tip is to set temporary_dir to a directory on the local host to avoid
1471 NFS traffic for temporary files.
1472
1473 It is recommended to use the same operating system version when using a
1474 shared cache. If operating system versions are different then system
1475 include files will likely be different and there will be few or no
1476 cache hits between the systems. One way of improving cache hit rate in
1477 that case is to set sloppiness to system_headers to ignore system
1478 headers.
1479
1481 The recommended way of combining ccache with another compiler wrapper
1482 (such as “distcc”) is by letting ccache execute the compiler wrapper.
1483 This is accomplished by defining prefix_command, for example by setting
1484 the environment variable CCACHE_PREFIX to the name of the wrapper (e.g.
1485 distcc). Ccache will then prefix the command line with the specified
1486 command when running the compiler. To specify several prefix commands,
1487 set prefix_command to a colon-separated list of commands.
1488
1489 Unless you set compiler_check to a suitable command (see the
1490 description of that configuration option), it is not recommended to use
1491 the form ccache anotherwrapper compiler args as the compilation
1492 command. It’s also not recommended to use the masquerading technique
1493 for the other compiler wrapper. The reason is that by default, ccache
1494 will in both cases hash the mtime and size of the other wrapper instead
1495 of the real compiler, which means that:
1496
1497 • Compiler upgrades will not be detected properly.
1498
1499 • The cached results will not be shared between compilations with and
1500 without the other wrapper.
1501
1502 Another minor thing is that if prefix_command is used, ccache will not
1503 invoke the other wrapper when running the preprocessor, which increases
1504 performance. You can use prefix_command_cpp if you also want to invoke
1505 the other wrapper when doing preprocessing (normally by adding -E).
1506
1508 • The direct mode fails to pick up new header files in some rare
1509 scenarios. See The direct mode above.
1510
1512 General
1513 A general tip for getting information about what ccache is doing is to
1514 enable debug logging by setting the configuration option debug (or the
1515 environment variable CCACHE_DEBUG); see Cache debugging for more
1516 information. Another way of keeping track of what is happening is to
1517 check the output of ccache -s.
1518
1519 Performance
1520 Ccache has been written to perform well out of the box, but sometimes
1521 you may have to do some adjustments of how you use the compiler and
1522 ccache in order to improve performance.
1523
1524 Since ccache works best when I/O is fast, put the cache directory on a
1525 fast storage device if possible. Having lots of free memory so that
1526 files in the cache directory stay in the disk cache is also preferable.
1527
1528 A good way of monitoring how well ccache works is to run ccache -s
1529 before and after your build and then compare the statistics counters.
1530 Here are some common problems and what may be done to increase the hit
1531 rate:
1532
1533 • If “cache hit (preprocessed)” has been incremented instead of
1534 “cache hit (direct)”, ccache has fallen back to preprocessor mode,
1535 which is generally slower. Some possible reasons are:
1536
1537 • The source code has been modified in such a way that the
1538 preprocessor output is not affected.
1539
1540 • Compiler arguments that are hashed in the direct mode but not
1541 in the preprocessor mode have changed (-I, -include, -D, etc)
1542 and they didn’t affect the preprocessor output.
1543
1544 • The compiler option -Xpreprocessor or -Wp,X (except
1545 -Wp,-MD,path, -Wp,-MMD,path, and -Wp,-D_define_) is used.
1546
1547 • This was the first compilation with a new value of the base
1548 directory.
1549
1550 • A modification or status change time of one of the include
1551 files is too new (created the same second as the compilation is
1552 being done). See Handling of newly created header files.
1553
1554 • The __TIME__ preprocessor macro is (potentially) being used.
1555 Ccache turns off direct mode if __TIME__ is present in the
1556 source code. This is done as a safety measure since the string
1557 indicates that a __TIME__ macro may affect the output. (To be
1558 sure, ccache would have to run the preprocessor, but the sole
1559 point of the direct mode is to avoid that.) If you know that
1560 __TIME__ isn’t used in practise, or don’t care if ccache
1561 produces objects where __TIME__ is expanded to something in the
1562 past, you can set sloppiness to time_macros.
1563
1564 • The __DATE__ preprocessor macro is (potentially) being used and
1565 the date has changed. This is similar to how __TIME__ is
1566 handled. If __DATE__ is present in the source code, ccache
1567 hashes the current date in order to be able to produce the
1568 correct object file if the __DATE__ macro affects the output.
1569 If you know that __DATE__ isn’t used in practise, or don’t care
1570 if ccache produces objects where __DATE__ is expanded to
1571 something in the past, you can set sloppiness to time_macros.
1572
1573 • The __TIMESTAMP__ preprocessor macro is (potentially) being
1574 used and the source file’s modification time has changed. This
1575 is similar to how __TIME__ is handled. If __TIMESTAMP__ is
1576 present in the source code, ccache hashes the string
1577 representation of the source file’s modification time in order
1578 to be able to produce the correct object file if the
1579 __TIMESTAMP__ macro affects the output. If you know that
1580 __TIMESTAMP__ isn’t used in practise, or don’t care if ccache
1581 produces objects where __TIMESTAMP__ is expanded to something
1582 in the past, you can set sloppiness to time_macros.
1583
1584 • The input file path has changed. Ccache includes the input file
1585 path in the direct mode hash to be able to take relative
1586 include files into account and to produce a correct object file
1587 if the source code includes a __FILE__ macro.
1588
1589 • If “cache miss” has been incremented even though the same code has
1590 been compiled and cached before, ccache has either detected that
1591 something has changed anyway or a cleanup has been performed
1592 (either explicitly or implicitly when a cache limit has been
1593 reached). Some perhaps unobvious things that may result in a cache
1594 miss are usage of __TIME__, __DATE__ or __TIMESTAMP__ macros, or
1595 use of automatically generated code that contains a timestamp,
1596 build counter or other volatile information.
1597
1598 • If “multiple source files” has been incremented, it’s an indication
1599 that the compiler has been invoked on several source code files at
1600 once. Ccache doesn’t support that. Compile the source code files
1601 separately if possible.
1602
1603 • If “unsupported compiler option” has been incremented, enable debug
1604 logging and check which compiler option was rejected.
1605
1606 • If “preprocessor error” has been incremented, one possible reason
1607 is that precompiled headers are being used. See Precompiled headers
1608 for how to remedy this.
1609
1610 • If “can’t use precompiled header” has been incremented, see
1611 Precompiled headers.
1612
1613 • If “can’t use modules” has been incremented, see C++ modules.
1614
1615 Corrupt object files
1616 It should be noted that ccache is susceptible to general storage
1617 problems. If a bad object file sneaks into the cache for some reason,
1618 it will of course stay bad. Some possible reasons for erroneous object
1619 files are bad hardware (disk drive, disk controller, memory, etc),
1620 buggy drivers or file systems, a bad prefix_command or compiler
1621 wrapper. If this happens, the easiest way of fixing it is this:
1622
1623 1. Build so that the bad object file ends up in the build tree.
1624
1625 2. Remove the bad object file from the build tree.
1626
1627 3. Rebuild with CCACHE_RECACHE set.
1628
1629 An alternative is to clear the whole cache with ccache -C if you don’t
1630 mind losing other cached results.
1631
1632 There are no reported issues about ccache producing broken object files
1633 reproducibly. That doesn’t mean it can’t happen, so if you find a
1634 repeatable case, please report it.
1635
1637 Credits, mailing list information, bug reporting instructions, source
1638 code, etc, can be found on ccache’s web site: https://ccache.dev.
1639
1641 Ccache was originally written by Andrew Tridgell and is currently
1642 developed and maintained by Joel Rosdahl. See AUTHORS.txt or
1643 AUTHORS.html and https://ccache.dev/credits.html for a list of
1644 contributors.
1645
1646
1647
1648ccache 4.2.1 07/21/2021 CCACHE(1)