/
Make Dependency Files for C/C++ Headers

Make Dependency Files for C/C++ Headers

When header files change we need to recompile the C/C++ source files which #include them.

This process of incremental compiles can be optimized make dependency files.

These end in the extension *.d. The contents of one might look like:

main.o: main.cpp ../FOO/FOOblah.h ../DST/DSTutils.h

Notice it is in fact a makefile rule.

One could in theory maintain these by hand - but it would be very error prone and time consuming.

Instead most good (not Microsoft) C++ compilers can generate these automatically using the -MMD flag. The precise flag will vary depending on the compiler.

To support using these files

# Include generate *.d files for header dependencies -include *.d

Dependency files can be problem for builds. If a change is made such that say a header file is deleted then old dependency files can break the build since they may refer to the deleted header file.

So typically when we clean the build, dependency files need to be deleted.

 

Related content

Why do we need header files?
Why do we need header files?
More like this
Dependency Tree
Dependency Tree
More like this
Simple make system - putting it all together
Simple make system - putting it all together
More like this
Make recipe rule
Make recipe rule
More like this
makefile - sandbox example
makefile - sandbox example
Read with this
How do you get a compiler to generate dependency files
How do you get a compiler to generate dependency files
More like this