Hello,
I am new to the whole concept of makefiles, and I'm trying to compile and build my program using a makefile template I have found. My project consists of three directories: "source", where my .cpp files are (source1.cpp, source2.cpp, source3.cpp), "include", where my .h files are (header1.h, header2.h, header3.h), and "obj", where the object files are to be stored (obj1.o, obj2.o, obj3.o). In the project root directory is my makefile, which is as follows:
Code:
EXEC = myexe
CC = g++
IDIR = include
SDIR = source
ODIR = obj
LDIR= -L
LIBS= -l
CFLAGS = -I$(IDIR1) $(LDIR) $(LIBS)
_DEPS = header1.h header2.h header3.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJ = obj1.h obj2.h obj3.h
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: $(SDIR)/%.cpp $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
$(EXEC): $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LDIR) $(LIBS)
clean:
rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
However, when I try to "make" my program, I get the following error:
"make: *** No rule to make target `obj/obj1.o', needed by `myexe'. Stop."
But as far as I can see, this rule is present, in the line
Code:
$(ODIR)/%.o: $(SDIR)/%.cpp $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
Have I made some errors in the makefile, or is it a different problem?
Thanks!