user1829358
user1829358

Reputation: 1091

Make -j works but -jN is not working

My Makefile looks as follows:

test:
    make clean
    make test2
test2: CXX=g++
test2: all

CPP_FILES := $(wildcard tmp/*.cpp)
OBJ := $(CPP_FILES:.cpp=.o)

all: ${OBJ}
    ${CXX} ${OBJ} ${LIB_PATH} ${LIBS} ${CXX_FLAGS} -o output.exe

%.o: %.cpp
    ${CXX} ${CXX_FLAGS} ${INCLUDE_PATH} -c $< -o $@

All the .o files can (and should) be build in parallel. This is working if I execute "make -j" but it fails if I limit the number of processes to some fixed number (say 4) via "make -j4". This will result in the following message:

make[1]: warning: jobserver unavailable: using -j1.  Add `+' to parent make rule.

Can someone please point me to my mistake? Why is "make -j" working while "make -j4" gives this error message?

Thanks!

Upvotes: 0

Views: 701

Answers (1)

Marc Glisse
Marc Glisse

Reputation: 7925

Please read the documentation for recursive calls in GNU make. Essentially, you need to call $(MAKE) or ${MAKE} instead of plain make or at least prefix the line in the recipe with + so that the sub-make can properly communicate with the parent make. This is particularly useful when you ask for job control.

Upvotes: 2

Related Questions