I have a *.H c++ headers in include/c++ folder, but even if I modified these files, make doesn't make again, what can I modify my Makefile to remake when those files modified?
If you're using GNU make and GCC, and building separate objects for each source (rather than building a program directly from all the sources) you can generate the necessary dependencies automatically. Add the following the the compiler's command-line arguments:
-MD -MP
-MD
will generate a .d
file alongside each object, containing make rules specifying all the headers it depends on. You could instead use -MMD
to exclude system headers (ones included with <>
rather than ""
), if you don't expect these to change. -MP
will generate dummy rules to ensure the target is rebuilt if any of the headers are deleted.
Then include all the .d
files from the makefile, using -include
so it's not an error if they're missing. I do this by transforming the list of object files:
-include $(all_objs:.o=.d)
Just make sure that your target depends on your headers.
your_app: $(SOURCES) $(HEADERS)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(SOURCES) $(LIBS) -o$@
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With