How to enable ccache on Linux
Solution 1
Download latest version of ccache for better performance.
After Downloading, Follow the steps as mentioned below:
A) Tar the file using the following command :
$tar -xvf ccache-3.2.4.tar.bz2
Note : I'm using ccache 3.2.4 Version.You can download the latest one.
B) Go inside ccache-3.2.4 folder and run the following commands:
$./configure
$./make
$ sudo make install
C) Go to your .bashrc and insert the following :
export CCACHE_DIR=/home/user_name/.ccache
export CCACHE_TEMPDIR=/home/user_name/.ccache
Note : Fill user_name with your User Name
D) Save your Bashrc and source it
$ source ~/.bashrc
E) To check ccache is working or not type :
ccache -M 10G : To Set the ccache Size to 10GB
F) To check ccache is working or not type :
ccache -s : To check ccache statistics
Solution 2
The ccache manual has a section called Run modes which describes the official ways of activating ccache, so I suggest reading the manual.
Also, as you already noted, Linux distributions often set up a /usr/lib/ccache directory which is designed to be prepended to PATH.
Solution 3
There are at least two methods:
i) Override the CC
, CXX
, ... flags in a Makefile. Within the R framework, a system and optional user configuration file is read, and I simply set
VER=4.7
CC=ccache gcc-$(VER)
CXX=ccache g++-$(VER)
SHLIB_CXXLD=g++-$(VER)
FC=ccache gfortran
F77=ccache gfortran
which also allows me to switch back and forth between gcc
versions. Now all compilations involving R use ccache
.
ii) For other uses, I have deployed the fact that /usr/local/bin/
is checked prior to /usr/bin
. So one can do
root@max:/usr/local/bin# ls -l gcc
lrwxrwxrwx 1 root root 15 Jan 27 11:04 gcc -> /usr/bin/ccache
root@max:/usr/local/bin# ./gcc --version
gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
root@max:/usr/local/bin#
and now gcc
is invoked via ccache
:
edd@max:/tmp$ cp -vax ~/src/progs/C/benfordsLaw.c .
`/home/edd/src/progs/C/benfordsLaw.c' -> `./benfordsLaw.c'
edd@max:/tmp$ time /usr/local/bin/gcc -c benfordsLaw.c
real 0m0.292s
user 0m0.052s
sys 0m0.012s
edd@max:/tmp$ time /usr/local/bin/gcc -c benfordsLaw.c
real 0m0.026s
user 0m0.004s
sys 0m0.000s
edd@max:/tmp$
Solution 4
Another possibility (instead of export CC=ccache
commented by Keltar), if $HOME/bin/
is listed in your $PATH
before /usr/bin/
, would be to make a symlink
ln -s /usr/bin/ccache $HOME/bin/gcc
Then every execvp(3) of gcc
would find that symlink
Arky
Arky is a technologist and a visual storyteller, who helps non-profits, social enterprises use Information and communication technology (ICT). He has been involved in Free and Open Source communities for over an decade and worked with various non-profits: Braille Without Borders (BWB), NGO Resource Center and Mozilla in Asia, SE. Asia and Africa. He now lives in Phnom Penh, Cambodia.
Updated on June 01, 2020Comments
-
Arky almost 4 years
There is very little documentation on enabling
ccache
on GNU/Linux. Here is a response from launchpad.net:At the moment, I think the best way to enable ccache is to add "/usr/lib/ccache" to the front of your path. If you want to enable it for all users by default, change the PATH variable in /etc/environment.
Can someone give me more information on enabling
ccache
?