Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printing all includes when compiling with GDB

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!!!

like image 293
DuduArbel Avatar asked Apr 20 '26 13:04

DuduArbel


1 Answers

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.

like image 109
Barry Gackle Avatar answered Apr 22 '26 03:04

Barry Gackle