0

I have a question regarding the include files.

Suppose you are using a define coming from windows headers. Of course, you can know what is the exact header which defines the macro. But the question is can we get the include chain and know which path causes the macro to be included?

E.g. I have the following structure

windows.h // a windows header defines a macro

header1.h <- windows.h // a <- b means a includes b
header2.h <- windows.h
header3.h <- windoes.h
header4.h <- header1.h, header2.h
header5.h <- header1.h, header4.h, header3.h

As you would expect, the real example can be a lot complicated with tones of macro definitions and ifdefs.

Now in our example.cpp we #include "header4.h" or #include "header5.h" or both together ant we use the macro in windows.h in our code. How to know what is the include chain?

E.g. for this example it could be header4.h - header1.h - windows.h

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
arsdever
  • 1,111
  • 1
  • 11
  • 32
  • 2
    Related [Displaying the #include hierarchy for a C++ file in Visual Studio](https://stackoverflow.com/questions/1137966/displaying-the-include-hierarchy-for-a-c-file-in-visual-studio) – ChrisMM Jul 13 '20 at 12:35
  • @ChrisMM Yes, it is related somehow. But I'm about easy functionality to just see the hierarchy. If I go through your suggestion, I have to compile the source, look where the header file is, then get the hierarchy. Although I didn't manage to find it in this way. – arsdever Jul 13 '20 at 12:43
  • 1
    That's why I said it as related, instead of duplicate. – ChrisMM Jul 13 '20 at 12:44

2 Answers2

1

With gcc 6.3.0 you can use a #pragma trick

$ cat so62875940.c
#include <stdio.h>
#pragma message "so62875940.c"

int main(void) {
    puts("foo");
    return 0;
}
$ gcc so62875940.c
so62875940.c:2:9: note: #pragma message: so62875940.c
 #pragma message "so62875940.c"
         ^~~~~~~

Then follow the includes order...

pmg
  • 106,608
  • 13
  • 126
  • 198
0

I think this link may help you. You could select Architecture->Generate Graph of Include Files/Generate Code Map for solution without Building.

Barrnet Chou
  • 1,738
  • 1
  • 4
  • 7