I have 3 files
main.cpp
a.h
b.h
main.cpp includes both a.h and b.h
b.h includes a.h
could anyone explain me how should I write a make file for this?
Is this correct?
objects = main.o
sources = main.cpp
myProj: $(objects)
g++ -o myProj $(objects)
main.o: a.h b.h
$(objects): $(sources)
g++ -c $(sources)
clean:
rm $(objects) myProj
I dont know how to specify the dependency of b.h on a.h
Since headers are always compiled as part of .c/.cpp file, there is no need to specify header-to-header dependency. The dependency that you have specified already is sufficient, because
main.cppwill recompile when a.h and/or b.h change.