How to use ccache selectively?

18,110

Solution 1

To bypass ccache just:

export CCACHE_DISABLE=1

For more info:

man ccache

...

        If you set the environment variable CCACHE_DISABLE then ccache will just call the real
       compiler, bypassing the cache completely.

...

Solution 2

What OS? Linux? Most packaged versions of ccache already put those symlinks into a directory, for example on my Fedora machine they live in /usr/lib64/ccache.

So you could just do

PATH=/usr/lib64/ccache:${PATH} make

when you want to build with ccache.

Most packages also install a file in /etc/profile.d/ which automatically enables ccache, by adding it to the PATH as above.

If that's the case on your system, just set CCACHE_DISABLE=1 (see man ccache for more info) in your environment to disable ccache - ccache will still be run, but will simply call the real compiler.

Solution 3

I stumbled across this for so many times now. For me the best solution was to do this:

export CCACHE_RECACHE=1;

From the ccache manpages:

Corrupt object files
   It should be noted that ccache is susceptible to general storage problems. If a bad object file sneaks into
   the cache for some reason, it will of course stay bad. Some possible reasons for erroneous object files are
   bad hardware (disk drive, disk controller, memory, etc), buggy drivers or file systems, a bad prefix_command
   or compiler wrapper. If this happens, the easiest way of fixing it is this:

    1. Build so that the bad object file ends up in the build tree.

    2. Remove the bad object file from the build tree.

    3. Rebuild with CCACHE_RECACHE set.

Solution 4

The alternative to creating symlinks is to explicitly use ccache gcc as the C compiler and ccache g++ as the C++ compiler. For instance, if your Makefile uses the variables CC and CXX to specify the compilers, you can build with make CC="ccache gcc" CXX="ccache g++" or set it up at configure time (./configure CC="ccache gcc" CXX="ccache g++").

Share:
18,110

Related videos on Youtube

Admin
Author by

Admin

Updated on April 19, 2022

Comments

  • Admin
    Admin about 2 years

    I have to compile multiple versions of an app written in C++ and I think to use ccache for speeding up the process.

    ccache howtos have examples which suggest to create symlinks named gcc, g++ etc and make sure they appear in PATH before the original gcc binaries, so ccache is used instead.

    So far so good, but I'd like to use ccache only when compiling this particular app, not always.

    Of course, I can write a shell script that will try to create these symlinks every time I want to compile the app and will delete them when the app is compiled. But this looks like filesystem abuse to me.

    Are there better ways to use ccache selectively, not always?

    For compilation of a single source code file, I could just manually call ccache instead of gcc and be done, but I have to deal with a complex app that uses an automated build system for multiple source code files.

  • foki
    foki over 3 years
    Well, it does not really work. For example, it does not work for the Bitcoin project that configures ccache through scripts. It would be great if we knew where ccaches cache files are, so we can just simply deleted them. As with any other caching solution.