# CMAKE Build in parallel Fail

**URL:** https://discourse.cmake.org/t/cmake-build-in-parallel-fail/2299
**Category:** Usage
**Tags:** os:linux
**Created:** [December 5, 2020, 5:35pm UTC](https://discourse.cmake.org/t/cmake-build-in-parallel-fail/2299 "2020-12-05T17:35:13Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![arturoar3nas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/arturoar3nas/32/935_2.png) [@arturoar3nas](https://discourse.cmake.org/u/arturoar3nas)
#### Post date: [December 5, 2020, 5:35pm UTC](https://discourse.cmake.org/t/cmake-build-in-parallel-fail/2299/1 "2020-12-05T17:35:14Z")

</div>

Hello,

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?

Thanks!

---

<div class="post-metadata">

### Author: ![erk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erk/32/114_2.png) [@erk](https://discourse.cmake.org/u/erk)
#### Post date: [December 5, 2020, 6:04pm UTC](https://discourse.cmake.org/t/cmake-build-in-parallel-fail/2299/2 "2020-12-05T18:04:15Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![arturoar3nas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/arturoar3nas/32/935_2.png) [@arturoar3nas](https://discourse.cmake.org/u/arturoar3nas)
#### Post date: [December 5, 2020, 6:14pm UTC](https://discourse.cmake.org/t/cmake-build-in-parallel-fail/2299/3 "2020-12-05T18:14:42Z")

</div>

Eric,

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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 5, 2020, 6:32pm UTC](https://discourse.cmake.org/t/cmake-build-in-parallel-fail/2299/4 "2020-12-05T18:32:51Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![arturoar3nas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/arturoar3nas/32/935_2.png) [@arturoar3nas](https://discourse.cmake.org/u/arturoar3nas)
#### Post date: [December 5, 2020, 6:45pm UTC](https://discourse.cmake.org/t/cmake-build-in-parallel-fail/2299/5 "2020-12-05T18:45:32Z")

</div>

Ben,

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

---

<div class="post-metadata">

### Author: ![erk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erk/32/114_2.png) [@erk](https://discourse.cmake.org/u/erk)
#### Post date: [December 5, 2020, 7:06pm UTC](https://discourse.cmake.org/t/cmake-build-in-parallel-fail/2299/6 "2020-12-05T19:06:29Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![arturoar3nas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/arturoar3nas/32/935_2.png) [@arturoar3nas](https://discourse.cmake.org/u/arturoar3nas)
#### Post date: [December 5, 2020, 7:49pm UTC](https://discourse.cmake.org/t/cmake-build-in-parallel-fail/2299/7 "2020-12-05T19:49:50Z")

</div>

Eric,

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`

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 5, 2020, 9:44pm UTC](https://discourse.cmake.org/t/cmake-build-in-parallel-fail/2299/8 "2020-12-05T21:44:24Z")

</div>

> [@arturoar3nas](#):
>
> `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.

---

<div class="post-metadata">

### Author: ![erk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erk/32/114_2.png) [@erk](https://discourse.cmake.org/u/erk)
#### Post date: [December 6, 2020, 11:35am UTC](https://discourse.cmake.org/t/cmake-build-in-parallel-fail/2299/9 "2020-12-06T11:35:47Z")

</div>

> [@arturoar3nas](#):
>
> 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

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).

---

<div class="post-metadata">

### Author: ![arturoar3nas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/arturoar3nas/32/935_2.png) [@arturoar3nas](https://discourse.cmake.org/u/arturoar3nas)
#### Post date: [December 8, 2020, 11:55pm UTC](https://discourse.cmake.org/t/cmake-build-in-parallel-fail/2299/10 "2020-12-08T23:55:41Z")

</div>

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!
