Object files are not created in sub directory but in main directory

81 views Asked by At

I have the following code in my makefile:

#Compiler
CC = g++

IDIR = headers
SRCDIR = sources
ODIR = obj
LIBS = -lncurses
CFLAGS = -I$(IDIR)

DE = Cow.h Sheep.h
DES = $(patsubst %,$(IDIR)/%,$(DE))

_O = Cow.o Sheep.o
OB = $(patsubst %,$(ODIR)/%,$(_O))

all: make
    ./make

make: $(OB) $(ODIR)/main.o $(DES)
    $(CC) -W -Wall -o $@ $^ $(CFLAGS) $(LIBS)

$(ODIR)/%.o: $(SRCDIR)/%.c $(DES)
    $(CC) -W -Wall -c -o $@ $< $(CFLAGS)

$(ODIR)/main.o: $(SRCDIR)/main.cpp
    $(CC) -c -o $@ $< $(CFLAGS)

But when I run make in the terminal, the object files are being created, but in the project directory (where the makefile is saved) and not in the obj sub directory.

0

There are 0 answers