views:

153

answers:

4

Hi,

I've got some big C programs, and I would like to know when I'm compiling this program, which header files are actually included...

The simplest solution would be to print the preprocessed code and look but do you know if there's a way to compile and at the same time showing what header files are included ?

A: 

Increase gcc verbosity and then run it through an own made filter program?

Marco van de Voort
no gcc -v does not print this information
LB
+4  A: 

You can use -MD option - see man gcc for details.

qrdl
A: 

Use gcc -M or gcc -MM. Adjust the output with sed if you like. If you use GNU make (and you should) you can wrap this up a into single tidy command.

Beta
+8  A: 

Use the -M option to output the dependencies. Use -MD to generate and compile. Use -MF to redirected to a file.

Also -MM allow ignoring the system file in the dependencies list.

gcc ... -M  -MF <output_file>     # generate dependencies
gcc ... -MD -MF <output_file>     # compile and generate dependencies
philippe
but from the manual : Passing -M to the driver implies -E, and suppresses warnings with an implicit -w. So the program is not actually compiled
LB
Yes, you have to use -MD to compile *and* generate the dependencies at the same time.
philippe
alright... thanks... ;)
LB