Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know which headers are included without looking at the preprocessed code in GCC?

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?

like image 582
LB40 Avatar asked Jun 26 '09 13:06

LB40


People also ask

Where does gcc look for headers?

GCC looks for headers requested with #include " file " first in the directory containing the current file, then in the directories as specified by -iquote options, then in the same places it would have looked for a header requested with angle brackets.

How do I find header files?

Most standard headers are stored in /usr/include . It looks like stdbool. h is stored somewhere else, and depends on which compiler you are using. For example, g++ stores it in /usr/include/c++/4.7.

Which option of GCC adds include directory of header files?

gcc -I adds include directory of header files.

Which option in GCC is used to specify the location of the .h files?

If you use both this option and the -isysroot option, then the --sysroot option applies to libraries, but the -isysroot option applies to header files. The GNU linker (beginning with version 2.16) has the necessary support for this option.


1 Answers

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
like image 71
philant Avatar answered Sep 19 '22 01:09

philant