0
votes

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
"Some situtation"? Does it mean it happens at random?Michael Chourdakis
Why did you tag this question with CMake?Kevin
@MichaelChourdakis anything above make -j 5 is failing as of now so I would say it is 100% reproducible which means when it runs with multiple cores the object files is not created by thenuser1885183
Seems a gcc bug then? It is the same with -j 2 ?Michael Chourdakis
Please show the complete makefile. My guess would be that you are not specifying the dependencies of target cars on the .o files correctly.G.M.

1 Answers

0
votes

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.