Reputation: 447
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
Upvotes: 1
Views: 150
Reputation: 1419
If you are at all any more confused on makefile concepts, I would recommend checking out this helpful tutorial.
http://www.cs.umd.edu/class/fall2002/cmsc214/Tutorial/makefile.html
Upvotes: 1
Reputation: 726479
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.cpp
will recompile when a.h and/or b.h change.
Upvotes: 2