11

When I run make -j3 to build in parallel, I get

warning: -jN forced in submake: disabling jobserver mode.

In the documentation I found the warning is emitted

if make detects error conditions related to parallel processing on systems where sub-makes can communicate.

What are these error conditions? What can I do to heal them or suppress the error message?

The makefile is generated from CMake, so I cannot (=I don't want to) edit the makefile.

usr1234567
  • 21,601
  • 16
  • 108
  • 128

4 Answers4

11

Usually this message occurres if you call make from your Makefile not by the variable $(MAKE)

Example:

Change

foo:
     cd foo/ && make foo

to

foo:
     cd foo && $(MAKE) foo
arved
  • 4,401
  • 4
  • 30
  • 53
  • I did not write the makefile myself, it is auto-generated by CMake. – usr1234567 Jul 06 '15 at 08:37
  • cmake usually does this right, maybe you are calling make from CMakeLists.txt – arved Jul 06 '15 at 09:12
  • Well, in my case this is exactly how I call the submake. I have a function `sub_make = $(MAKE) -C $(TOPDIR)/subdir/$(1) $(2)`, and then I do e.g. `$(call subproject,all)`. So it is `$(MAKE)` as you say. And still I get the warning. – Hi-Angel Sep 15 '20 at 15:29
  • Okay, [I figured the reason](https://stackoverflow.com/questions/6783243/functions-in-makefiles#comment113020403_6784014). It turns out, for some reason `$(MAKE)` call won't work as it should if you call it from a Make function. In such cases the function must have `@+` symbols after equality sign. So, given my previous example, to make it work I'd have to declare it as `sub_make = @+$(MAKE) -C $(TOPDIR)/subdir/$(1) $(2)` – Hi-Angel Sep 16 '20 at 06:44
3

You call make -j3 for you top-level Makefile, which means that up to 3 targets can be built simultaneously (make uses 3 threads to build). Your top-level Makefile (generated by CMake) run another make (which is called sub-make). And in this invocation another -jN option is used. So instead of using common jobserver for both makes, sub-make uses another N threads to build its targets. So up to 3 + N threads in total are used for building. So this is what this warning about.

To enable common jobserver for parent make and sub-make, there are 2 requirements:

  • Explicit -jN option mustn't be passed to sub-make. Call sub-make without this argument.
  • Sub-make must be called using $(MAKE) expression (not just plain make). Alternatively the + prefix can be added before make command. See this answer for details.

If both requirements are satisfied, then, when you run make -jN for you top-level Makefile, parent make and child make use N threads in common for building.

anton_rh
  • 8,226
  • 7
  • 45
  • 73
2

This is related to multi-threaded make feature. It happens when there is yet another multi-threaded make inside a make process that is already multi-threaded. As there is second level of multi-threaded make, the internal synchronization is not available.

It is possible to fix this by -j parameter.

make -j 1

The code above will avoid multiple thread and it will remove the warnings.

Again, we can use -j parameter in the makefile as well.

target:
    $(MAKE) -j 1 -C ${SUBDIR} $@

The above rule will not spawn threads for submake and it will avoid the warning.

KRoy
  • 1,290
  • 14
  • 10
  • 2
    Thanks for sharing these insights. But with CMake generates the Makefiles and I don't have control over them. As it seems to be fixed in upstream CMake and/or GNU make, I am fine with this topic. – usr1234567 May 13 '17 at 06:57
1

With newer versions of GNU make (4.0) and CMake (2.8.6 and 3.3) I can no longer reproduce the warning. One of these got fixed in the meantime.

usr1234567
  • 21,601
  • 16
  • 108
  • 128