A Code Monkey's Blog

colorgcc and ccache work together

The plain and lengthy output of g++ was a hurt to eye when your code contains a lot of template programming. colorgcc can make life easier. It can work well with ccache but needs a bit trick to connect them together. I would like to recommend the solution at

http://stackoverflow.com/questions/1995415/g-colorgcc-and-ccache

I copy the main part right here:

The Short Answer

Without patching colorgcc.pl itself, the easiest way to fix this is to write yourself a simple wrapper script for each command, calling ccache with the appropriate arguments for that command, and passing along the arguments the script received (effectively currying the call to ccache.)

E.g., for gcc:

  • /usr/local/bin/ccache-gcc.sh:

    #!/bin/bash ccache /usr/bin/gcc "$@"

  • ~/.colorgcc:

    gcc: /usr/local/bin/ccache-gcc.sh

and for g++:

  • /usr/local/bin/ccache-g++.sh:

    #!/bin/bash ccache /usr/bin/g++ "$@"

  • ~/.colorgcc:

    gcc: /usr/local/bin/ccache-g++.sh

There are ways to clean this up so that you only use a single script, with symlinks for each variant, but those are beyond the scope of this answer, and I leave them to you as an excercise :-)

GCC tips