0

There are some object files say a.o and b.o created when the binary engine is created.

Makefile

.PHONY all
all: engine cars

Now this second binary cars needs .o files a.o and b.o created while creating binary engine

The problem here is I am using make -j for compilation which in some situation results in the object files not created and hence undefined reference errors. The issue is not seen with make -j 5.

Is there someway I can make it run parallely with make -j

1 Answers1

0

Typically, make, even with -j specified, will try to build the dependencies from left to right. So in your working case, it starts by building engine first, and then it builds car. If engine finishes building before car starts, then you're fine, otherwise you're not.

In your case, I'm imagining that you have four other high level processes which are being built along with engine, that supersede the running of car, and thus engine happens to finish before car when you build with low -j values.

In any case, you are missing some dependencies. You need either:

car : a.o b.o

if car is dependent on those two. If a.o and b.o are side effects of the engine recipes, then you might do

car : engine

Note: even though your makefile happened to work with low -j values, Makefiles should not assume a left-to-right build order, and should not make any assumptions about running time of any recipes -- so you're makefile was indeed broken to begin with.

HardcoreHenry
  • 5,909
  • 2
  • 19
  • 44