Skip to content

Instantly share code, notes, and snippets.

@foxoman
Last active September 18, 2016 01:08
Show Gist options
  • Save foxoman/9556fd00516d578b39eb1f7f79ae1114 to your computer and use it in GitHub Desktop.
Save foxoman/9556fd00516d578b39eb1f7f79ae1114 to your computer and use it in GitHub Desktop.
Speeding up compilation on Ubuntu with Qt Creator using ccache
ccache is a clever tool that wraps you compiler (g++ or mpicxx) and understands whether the file you are compiling has been compiled before with exactly the same contents and settings. If it has, it just returns a cached result.
Unlike regular make, ccache is extremely good at detecting the true state of what you are compiling. I have never had any trouble with ccache.
This really speeds up the compilation when you are using make clean, especially if you are switching git branches. In other words, it is a much simpler solution to achieve fast compilation with git branches than to create separate build folders for each branch.
To enable ccache, install it with
sudo apt-get install ccache
and add the following to your .pro file:
QMAKE_CXX = ccache g++
Replace g++ with mpicxx if you are using MPI.
The make -j flag
I realized when compiling the Qt source that make has a -j flag that enables threaded compilation on all available processors on the machine. This also speeds up compilation significantly, and I made a 3.55x performance gain on a 4 core CPU. To enable this flag, go to the Projects view in Qt Creator and add the following arguments to the make build step:
-j
If you prefer not to use all available processors for compilation, you may add a number after -j to set the number of processors. For instance make -j 3 would compile with 3 processors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment