Hello I need to create a makefile for 2 separated cpp programs that are in one directory. I have got this code, but it’s not working correctly. The .o files do not get created.Thank you
OBJS = a b
EXEC = first_run second_run
#------ constant definitions
ALL_OBJ = $(OBJS:%=%.o)
all: $(EXEC)
clean:
$(RM) $(EXEC) $(OBJS) $(ALL_OBJ); make all
CC = g++
DO_OBJS = $(CC) -cpp -o $@.o $@.cpp; touch $@
DO_EXEC = $(CC) -s -o $@ $(ALL_OBJ)
#------ now compile
$(OBJS): $(@:%=%.o)
$(DO_OBJS)
$(EXEC): $(OBJS)
$(DO_EXEC)
There are a couple of problems with your file, but the major problem seems to be that you try to link both source files to a single executable. You have to list each program and its dependencies on its own.
Try instead this simple Makefile: