Reputation: 25
how can i include a re-compilation/update for my own ".h" files within my makefile.
This is my makefile:
COMPILER = g++
SOURCES = main.cpp
APP = executable/main
OBJECTS = $(SOURCES:.cpp=.o)
all: $(SOURCES) $(APP)
$(APP): $(OBJECTS)
$(COMPILER) $(OBJECTS) -o $@
clean:
rm -rf *.o $(APP)
suppose now i want to re-compile the project but i just modified whatever.h and whatever1.h. these files are included in the header of main.cpp.
Upvotes: 0
Views: 614
Reputation: 99084
It won't do any good to add these files to the list of dependencies of $(APP)
. That will cause Make to relink (that is, build main
out of main.o
) but not recompile (that is, build main.o
out of main.cpp
, whatever.h
and whatever1.h
). The behavior of the executable will not change-- it will not reflect the changes you've made to the headers.
You should add these files to the list of prerequisites of the object file:
main.o: whatever.h whatever1.h
Upvotes: 3
Reputation: 1605
Add header files in your app dependency list:
COMPILER = g++
SOURCES = main.cpp
HEADERS = whatever.h whatever1.h
APP = executable/main
OBJECTS = $(SOURCES:.cpp=.o)
all: $(SOURCES) $(APP)
$(APP): $(OBJECTS) $(HEADERS)
$(COMPILER) $(OBJECTS) -o $@
clean:
rm -rf *.o $(APP)
Upvotes: -1