I have a project with several folders:
Project
|_ include/
| '- Eigen/
|_ obj/
|_ src/
|_ makefile
All .cpp
files are in src/
and have dependencies with several .hpp
files in include/
and with the Eigen library too.
Now, everytime I edit a source file I can use the make command, however when I change a header file it tells me that all
is up to date.
I've tried several examples that I found on similar questions and I've read some tutorials on makefiles but I cannot manage to make it work properly.
Also every time it compiles, if a .cpp that uses the Eigen library was modified, it takes very very very long, like it is reading again through all Eigen headers.
My makefile:
CC := g++
SRCDIR := src
OBJDIR := obj
TARGET := main
JPEG_LIB_DIR = /usr/local/lib
SRCEXT := cpp
SOURCES := $(shell find $(SRCDIR) -name *.$(SRCEXT))
OBJECTS := $(SOURCES:$(SRCDIR)/%.$(SRCEXT)=$(OBJDIR)/%.o)
CFLAGS := -W -Wall -g -rdynamic -std=c++11
LIB += -pthread
LIB += -ljpeg
LFLAGS += -L$(JPEG_LIB_DIR)
INC += -I include
.PHONY: clean
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(LFLAGS) $^ $(LIB) -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(OBJDIR)
$(CC) $(INC) $(CFLAGS) -o $@ -c $<
clean:
$(RM) -r $(OBJDIR) $(TARGET)
(I've tried this and that but it won't even compile).
Thank you!