2

I compile my C++ code using gcc (4.6.3), and want the compiler to print all the includes it uses. In MS VS it is done simply by adding a /showIncludes flag, and the output looks like this:

1> File.cpp
1> including file : A.h
1> including file :  B.h
1> including file :   C.h
1> including file :  B2.h

Is there such option in gcc?

Thanks!!!

dbrank0
  • 9,026
  • 2
  • 37
  • 55
DuduArbel
  • 1,100
  • 1
  • 12
  • 25
  • 2
    gdb is a debugger. Did you mean gcc or g++? http://stackoverflow.com/questions/4479049/show-include-equivalent-option-in-g – Retired Ninja May 10 '15 at 06:35

1 Answers1

2

gcc has a -v flag. That will show you exactly what files it is including, as well as where it is searching for includes.

If you want the complete dependency tree, then use the -M flag. This is used to list not only the files directly included by gcc, but the files included by those as well. Using plain "gcc -M" will list everything, including the entire tree of standard library includes. If you are just analyzing your own code base, try "gcc -MM" to limit the inclusion of system files.

The search term you want is "dependency", as most of these options are commonly used in the gcc world to build machine readable files (usually with a *.d extension) for the Make utility to use. Try googling that if you need to drill down to more detail on this family of options.

Barry Gackle
  • 829
  • 4
  • 17
  • Thanks, but this is not what I need. in the example above, you can see, while compiling!!!, that File.cpp has 2 inlcudes, to B.h and B2.h, and also that file B.h has an include to C.h, etc. – DuduArbel May 10 '15 at 10:14
  • Ah, I misunderstood what you were after; thanks for taking the time to correct. I'll update the answer to include that. – Barry Gackle May 10 '15 at 18:25