I have the following makefile
SRCS = a.cpp
OBJS = $(SRCS:.cpp=.o)
all: $(MAIN)
@echo Compiled successfully
$(MAIN): $(OBJS)
$(CXX) $(LFLAGS) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
.cpp.o:
$(CXX) $(LFLAGS) $(CFLAGS) $(INCLUDES) -c $< -o $@
When I run make all
initially no .o
files exist hence the .cpp.o:
rule is executed (a.o: a.cpp), and then I see the $(MAIN):
rule being executed – however – it seems like the $(MAIN):
rule is executed before the a.o object file is created, and make fails saying that the ‘a.o’ file could not be found..
This doesn’t happen all the time, which suggests some race condition, which could happen if the $(MAIN):
rule does not ‘wait’ until the .cpp.o:
has finished..
michael mitsenmacher is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.