As far as I know, ccache speed up compilation by catching previous compilations and detecting when the same compilation is being done again. however, makefile do the same thing. so why should we need ccache? when is the case we use it? thanks!
2 Answers
Aside from the dubious benefit of speeding up clean builds necessitated by a broken buildsystem, and the mere accidental benefit of having a shared cache, there exists a legitimate use of ccache even for an isolated flawless mtime based buildsystem:
When you are jumping back and forth between branches (not talking about separate directories), or rebasing, such that you end up touching a whole bunch of files, or if you're unlucky, a central header (like config.h) that's included all over the place, your flawless mtime based buildsystem would dutifully rebuild everything. If you have built mostly the same state some time in the past, ccache will speed up this rebuilding.

- 5,520
- 4
- 32
- 38
From http://ccache.samba.org/:
If you ever run
make clean; make
, you can probably benefit from ccache. It is common for developers to do a clean build of a project for a whole host of reasons, and this throws away all the information from your previous compilations. By using ccache, recompilation goes much faster.Another reason to use ccache is that the same cache is used for builds in different directories. If you have several versions or branches of a software stored in different directories, many of the object files in a build directory can probably be taken from the cache even if they were compiled for another version or branch.
A third scenario is using ccache to speed up clean builds performed by servers or build farms that regularly check that the code is buildable.
You can also share the cache between users, which can be very useful on shared compilation servers.

- 79,602
- 28
- 170
- 210
-
5when we run make clean, we want to clean all the .o file and recompile. So, if we want to save previous compilations to cache, why not just avoid running make clean before? – chicklet Apr 13 '12 at 07:52
-
5You might have just changed your `Makefile`. Or you might be trying to bisect a bug without `git`: if you unpack a tarball of an older version of the project, `make` will think the binaries are up-to-date because they are newer than the source files - but it would be wrong! In both those situations, `make clean` is needed. `ccache` won't make the same mistake because it uses hashes instead of timestamps, and it is very careful to only engage in situations where the output would be identical. – joeytwiddle Aug 05 '14 at 19:45