CMAKE Build in parallel Fail


Always when I try to build some project with

cmake --build <some dir> -j n

this fail in most cases. How I can fix this?


You should give us more informations on how it fails. From my personal experience if parallel build fails (sometimes but not always) and sequential build never fails you probably miss some dependencies in you project so that parallel build cross the unspecified dep more often, because it start at several places in the dep tree.

Which version of CMake are you using?
Which generator do you usually use?


Thanks for your fast reply, yes when I attempt to build in sequential mode never fail but in most of case fail in parallel mode because cmake expect some .o or some dependency that is not build yet, then, I don’t know how to synchronize the build process.

I’m working with cmake version 3.14.5 and Unix Makefiles.

If target X is failing because something about target Y is missing, you’re missing either a target_link_libraries(X ${vis} Y) or an add_dependencies(X Y) somewhere.


This is not the case because in sequential build work fine.

On the contrary this must be the case otherwise parallel build wouldn’t fail.
A sequential build is only one of the many path to build all your artefact.
Try to switch from from “Unix Makefile” to “Ninja” and you’ll probably encounter the problem sooner because the default behavior of Ninja is to build in parallel.

Could you share the code which fails to build in parallel?


Let me try switching to Ninja.

The code is pretty large but the error logged make reference to undefined references to some functions and this is normal because are not build and linked yet, then I get this message:

make[1]: *** Waiting for unfinished jobs...

Followed by:

make: *** [Makefile:152: all] Error 2

This is make reporting about your error to you. The actual error which caused this is somewhere earlier in the build log.

Ok as indicated by @ben.boeckel this is the make error which is only the consequence of a missing dependency because make assumes a target may be built before its dependencies are built.

You have to have a look at the target which fails to build and probably add a dependency between the one failing and the one not yet built.

In any case be sure that having a sequential build that works does not ensure that your set of dependencies are complete. I have seen a build working for more than a year sporadically failing as soon as we did upgrade a CI server going from 4 cores to 10 cores. We had to track the missing deps in order to have a robust build again.

As @ben.boeckel told you may be missing a target_link_librairies or add_dependency (if you have custom command/target in your build for example).

Ben, Eric

Thanks a lot for your replies, let me check for any missing dependency and I’ll come back with some feed back at soon I can.

Best Regards!