开发者

How to use ccache selectively?

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开发者_如何学C 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.


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.

...


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.


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.


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++").

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜