How to speed up compilation of Ubuntu apps (make, cmake, gcc)
772
I am compiling some programs here and I have 4 cores. Is there a way to tell make, cmake or gcc to compile using all cores or something to that affect?
If you have multiple machines, give distcc a go. On the involved machines, sudo apt-get install distcc. Assuming that your build machine is 192.168.1.1:
on the helper machines, run:
sudo distccd --log-file=/tmp/distccd.log --daemon -a 192.168.1.1
On the build machine, before running configure or cmake you have to specify hosts that you want to use for the build process. Optionally, specify the number of simultaneous jobs after a slash (defaulting to 4):
If a package supports it you can use the
-j
flag to allow parallel jobs running, e.g.:More details on this flag can be found in the Stackoverflow question Why does make -j perform better when it is passed a number larger than the number of cores available?.
Distributed compilation
If you have multiple machines, give distcc a go. On the involved machines,
sudo apt-get install distcc
. Assuming that your build machine is 192.168.1.1:on the helper machines, run:
On the build machine, before running
configure
orcmake
you have to specify hosts that you want to use for the build process. Optionally, specify the number of simultaneous jobs after a slash (defaulting to 4):Make the compiler use distcc:
Now
configure
orcmake
the application and build with:Note that if you've put
/usr/lib/distcc
twice in your PATH, it'll fail. Be sure to set/usr/lib/distcc
only once in yourPATH
.For more details, see the manual pages for distcc(1) and distccd(1).