Reputation: 7614
I have a macro which is used in afile.c
and bfile.c
(both in module A)
This macro is in aheader.h
Both of these are in different modules/directories and aheader.h module is complied before module A is complied.
Now one way is to do #include "aheader.h"
in each of the .c files.
But instead of doing this, is there a way to make some addition in the Makefile (like adding it to the list of headers) for module A,
so that aheader.h
is picked for everywhere the macro is used?
Upvotes: 2
Views: 1445
Reputation: 16449
#include "aheader.h"
is the simple and correct thing to do. C has no feature to auto-include headers when a macro is used.
If you insist on doing it in the makefile, you can add -include aheader.h
as a compilation flag. It will include it in all files.
It's possible to use the makefile to add this flag only when the macro is found in the C file, by using grep
. But it's complicated makefile work, and I think you're better off without it.
Upvotes: 3