Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top