Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Dependency files are a useful tool in optimizing the speed of incremental compiles of When header files change we need to recompile the C/C++ code. They are a solution for answering the question:

  • When do I need to recompile this file?

This is what the contents of a dependency file looks 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:

Code Block
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

Code Block
# 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.

Couple of questions about dependency files:

...

What extension do they typically have?

  • *.d

Does the compiler use these files?

...

.

...

How does GNU make typically use them?

...

Typically we have include statement in the make file:

...