Recently I found out about such a program as ccache.

Excerpt from Wikipedia:

Using csache can significantly speed up the build of some packages or projects that are compiled several times, since only files that have changed since the last compilation will be recompiled.

What is the advantage of ccache over make in terms of this item (or are there other advantages)?

When does ccache apply?

  • short answer: these are completely different programs. compare meaningless: they are not interchangeable. - aleksandr barakin
  • @alexanderbarakin when faced with this program, I don’t understand why it should be used at all, if there is make. Therefore, I would like to know if someone can use something. Hooked the phrase "significantly speed up the assembly," but those mechanisms that are visible, at first glance, no better than make. - Maxim Gusev

2 answers 2

short answer: these are completely different programs. to compare them is pointless: they are not interchangeable.


slightly longer answer:

The make program is completely unrelated to compilers, and the ccache program is the compiler cache for C, C ++, Objective-C, and Objective-C ++ . The standard way to use it is to “substitute” the compiler (for example, by creating symbolic links of the form /usr/local/bin/cc ).

The basic idea is to detect when it was previously issued. (my free translation: the basic idea is to determine when you compile the same code a second time and use the result that is already ready ).


very simple, without nuances and details

in the compilation process creates a so-called. object module ( object file ) . for example, as a result of executing the cc -c файл.c will be received

which can later be used by the linker ( linker ) to create an executable file with the program.

quite often the executable file is composed of several object modules. and if we “head on” automate this process ( cc -c файл1.c && cc -c файл2.c && cc файл1.o файл2.o -o программа ), then each time you call this long command all will be compiled again and again source files, even if we made a change, for example, to only one of them.

To avoid recompilation of unchanged files, you can use, for example, the make program, which does not actually compile, but helps to avoid performing repeated actions where it is not required. well, if there are appropriate rules in the makefile , where the dependencies between the files and the ways of updating those files that need updating are described.

An example of such rules:

  • if файл.c newer than файл.o , then run the command cc -c файл.c
  • if the файл.o newer программа , then run the cc файл.o -o программа command. The cc файл.o -o программа

All this works fine if we have one project (and the object files are not deleted after compilation). and if there are several projects, and in all of them (or at least some), the файл.c with identical content is used? the make program here does not help to avoid multiple compilations of the same file in different projects.

here, the ccache program mentioned above can help us (if we “replace” the cc program with it).

the algorithm is simple:

  1. if the transferred file has not yet been compiled, then compile it by calling the "real" cc , and copy the result (object module) into the cache.
  2. if the transferred file has already been compiled, then copy the ready object module from the cache.

It is not a problem to identify the cached output. (my free translation: to determine that the file is “the same”, hashing of various types of information is used, which should be unique for a given compilation, and these hash sums allow us to calculate which of the cached results should be used ).

    The advantage of ccache is just in the behavior you cited. make compiles the package each time the package is built. ccache , in contrast to make , looks before compiling - or maybe this work has already been done? And if a file has already been compiled, then it is not re-compiled, but the result is already compiled. Of course, ccache is smart enough to track that although the file was compiled earlier, but now there are changes in it and therefore need to be re-compiled.

    When does it apply?

    In those when you regularly have to recompile the same programs and there is a desire to speed up this process. For example, ccache extremely useful in the Gentoo distribution, where the installation of programs is precisely to compile them from source.

    • make also checks if the file has been modified and does not recompile the unchanged files. Also, recompilation is possible when changing the included header file. Based on this, the question was raised ... There are no differences - make is much higher than the functional. - Maxim Gusev
    • when assembling a package , it is probably worth specifying exactly what is meant in this case by the word “package”. and provide information on why exactly the make program in this particular case is not able to accomplish what it was written for: update only those goals that are older than the prerequisites. - aleksandr barakin