c++ - building program with make and automatic dependencies -
i have written simple c++ program, , first time want compile , link using makefile. challenge want make makefile, lists dependencies itself. following this tutorial. program consist of main.cpp, ext1.cpp , ext1.h. following tutorial, have following makefile
vpath = src include cppflags = -o include cc = gcc sources = main.cpp \ ext1.cpp -include $(subst .c,.d,$(sources)) %.d: %.c $(cc) -m $(cppflags) $< > $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$ when run message: make: *** no targets specified , no makefile found. stop. not clear me missing in case?
you trying @ once.
step 1. first makefile should build executable without attempting automatic dependency detection.
vpath = include src cppflags += -iinclude cc = gcc exec: main.o ext1.o $(cc) $^ -o $@ %.o: %.cc $(cc) -c $(cppflags) $< -o $@ main.o ext1.o: ext1.h step 2. once works perfectly, can put header dependencies in separate files:
makefile:
vpath = include src cppflags += -iinclude cc = gcc exec: main.o ext1.o $(cc) $^ -o $@ %.o: %.cc $(cc) -c $(cppflags) $< -o $@ -include *.d main.d:
main.o : ext1.h ext1.d:
ext1.o: ext1.h step 3. once that works perfectly, can generate dependency files automatically:
vpath = include src cppflags += -iinclude cc = gcc exec: main.o ext1.o $(cc) $^ -o $@ %.o: %.cc $(cc) -c -mmd $(cppflags) $< -o $@ -include *.d
Comments
Post a Comment