I have a small project with the files in src folder: functionAdd.cpp; functionSubtract.cpp; main.cpp and my Makefile. In include folder i got functionAdd.hpp and functionSubtract.hpp. First i had an error like, can't find these two .hpp file. After referencing to this answer i made new Makefile. so here what i did:
CC = g++
HEADER1 = home/administrator/Desktop/makefile-test/include/functionAdd.hpp
HEADER2 = home/administrator/Desktop/makefile-test/include/functionSubtract.hpp
CFLAGS = -c -Wall -Iinclude
all:calculation
calculation: main.o functionSubtract.o functionAdd.o
$(CC) main.o functionSubtract.o functionAdd.o -o calculation
main.o: main.cpp $(HEADER) $(HEADER2)
$(CC) $(CFLAGS) main.cpp
functionSubtract.o: functionSubtract.cpp $(HEADER2)
$(CC) $(CFLAGS) functionSubtract.cpp
functionAdd.o: functionAdd.cpp $(HEADER1)
$(CC) $(CFLAGS) functionAdd.cpp
clean:
rm -rf *o calculation
Now the error message is: make: *** No rule to make target home/administrator/Desktop/makefile-test/include/functionSubtract.hpp, needed by main.o. Stop.
/
on front of thehome/...
paths:/home/...
. Aresrc
andinclude
subdirectories of the same parent directory? If yes there are simpler solutions than specifying the absolute paths. – Renaud Pacalet