24n8
24n8

Reputation: 2236

What is the point of including header files in a makefile?

My C++ instructor told us to include headers in the makefiles as a dependency. But I don't see the purpose of this when the respective source file, say example.cpp already has a #include "example.h". So it seems to me including them or not doesn't change the compilation Could someone explain the purpose of their inclusion in a makefile?

The one thing that did come across my mind that makes it useful to have as a dependency has to do with a process like:

(1) execute make all using a makefile that doesn't include the headers as dependencies in the makefile

(2) modify some header file and no other files.

(3) run make all again without doing a make clean.

I think this procedure would lead to nothing to be done by make because the makefile directives are not picking up on the changes in the header file?

Upvotes: 0

Views: 219

Answers (1)

user10762593
user10762593

Reputation:

The point of 'make' is to automatically handle dependencies. So you'd want to tell it about dependencies. Otherwise, as you observe, it cannot rebuild that which needs rebuilding,

Upvotes: 1

Related Questions