I am using GCC 4.7 and compiling my C++ code-project. The code consists of files distributed in directories.
On RHEL server I use, there are 16 cores, still the compilation speed is quite slow. Can you suggest possible alternatives or options of makefile, which may help in compiling fast. I have tried -j but it only compiles some folders and stops; does not compile the main binary.
I will be grateful for any help.
if your makefile fails when you compile with
-jbut works fine without, then you may need to fix your makefile to work properly with parallel compilation. Otherwise, those other 15 cores are of no use to you.It’s not uncommon for less experienced makefile writers to write something like:
to mean “to build final, first build step1, then step2, then step3”. This works fine when you are running with the default setup of
-j 1becausemakehappens to build each of the dependencies in left-to-right order. But if you use-j 20(say) then it will attempt to build them in parallel. It will attempt to start building all 3 steps at once, without first waiting until each successive step is complete.The correct way to write this is:
This tells
makeexactly what’s happening: to buildfinalyou first need to buildstep3, for which you needstep2, for which you needstep1.