The good news is there IS a tool that can help address all of these shortcomings: ccache from the author of Samba. Ccache analyses and stores your object file during compilation, so they can be automatically substituted from the cache in future cases where the same compiler, options, and code is present. The best part is ccache guaranties that the cache will provide the same result as the real compiler, including warnings, and will fall back to the real compiler if there is any ambiguity. While ccache is limited to single file C, C++, Objective-C, or Objective-C++ files from a GCC style compilers, it will transparently pass other languages, multi-file compiling, and linking onto the real compiler.
Installing & Using ccache under CentOS 7
Ccache can be found in the terrific EPEL (Extra Packages for Enterprise Linux), if you don’t already have EPEL enabled it is just a single command:
For small compile jobs you can now directly use /usr/lib64/ccache/{gcc,g++} to compile your code as normal.
View ccache statistics
Finally cmake can be configured to use ccache (when present) directly in your MakeLists.txt file. If you are interested please see my cmake for HHVM commit that was recently accepted by Facebook.
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-6.noarch.rpmInstall ccache
sudo yum install ccache -yBy default the ccache package installs symbolic links such as /usr/lib64/ccache/{gcc,g++,etc} that point to ccache and can be used directly in place of the various supported compilers. If desired you can put symbolic links in your path before your real compiler and use ccache automatically, however for this example we’ll assume you don’t wish to do that.
For small compile jobs you can now directly use /usr/lib64/ccache/{gcc,g++} to compile your code as normal.
/usr/lib64/ccache/g++ mycode.cppIf you are using configure or make, you can override your C/C++ compiler with the following option:
{configure,make} “CC=’ccache gcc’ CXX=’ccache g++’”Finally, for cmake simply include the following:
cmake -D CMAKE_CXX_COMPILER="/usr/lib64/ccache/g++" -D CMAKE_C_COMPILER="/usr/lib64/ccache/gcc" .
Advanced ccache
Ccache also includes a utility to report cache statistics and configure cache options.View ccache statistics
ccache -sSet ccache’s cache size to 5G with no item limit
ccache -M 5G –F 0Ccache can also share a cache between users, or even between machines with NFS! This is great for a group of developers with a large code base. Of course there are some limitations, so be sure to check the ccache documentation for details.
Finally cmake can be configured to use ccache (when present) directly in your MakeLists.txt file. If you are interested please see my cmake for HHVM commit that was recently accepted by Facebook.
For More Information:
- Ccache Website: https://ccache.samba.org
- Ccache Documentation: https://ccache.samba.org/manual.html
No comments:
Post a Comment