I get the following error :
make : *** no rule to make target obj/Divers.o, needed by main. Stop
Here is what my makefile look like :
IDIR = include
ODIR = obj
SDIR = src
BDIR = bin
CC = g++
CFLAGS = -g -Wall -Wextra -std=c11 -I$(IDIR)
PROG = main
_DEP = Divers.h ArbresSyntaxiques.h
DEP = $(patsubst %,$(IDIR)/%,$(_DEP))
_OBJ = Divers.o ArbresSyntaxiques.o Main.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
.PHONY: run all remake clean delete
all: $(PROG)
run : all
./$(PROG)
$(PROG) : $(OBJ)
$(CC) $(CFLAGS) -o $@ $^ -lm
$(ODIR)/%.o : $(SDIR)/%.c $(DEP)
$(CC) $(CFLAGS) -c -o $@ $<
clean :
rm -f $(ODIR)/*.o
delete : clean
rm $(PROG)
Finally my folder is structured like this :
include :
ArbresSyntaxiques.h
Divers.h
obj : (Empty)
src :
AbresSyntaxiques.cpp
Divers.cpp
Main.cpp
makefile
Like @kiner_shah mentioned under the comments.
To compile C++ instead of C, the file extension obviously needs to be either .cpp
or .c++
on the following line $(ODIR)/%.o : $(SDIR)/%.c $(DEP)
I also had a typo in what of my cpp files' name