Dexter
Dexter

Reputation: 1337

gcc - how to find path of header include file

Do we have any option in gcc to find from where a particular file header is included. I have the following scenario :

file_1.h : declare type of type_1

file_2.h :

type_1 var;

I want to check where was file_1.h included in the library that i am creating.

Upvotes: 6

Views: 5160

Answers (2)

Jonathan Wakely
Jonathan Wakely

Reputation: 171303

If you look at the preprocessed output it will show the headers that were included, in the order they were included, so you can see where file_1.h appears and work backwards to see which file included it, and which file included that etc.

The -E option tells GCC to only perform the preprocessing step and to stop before compilation.

Upvotes: 0

P.P
P.P

Reputation: 121397

gcc has an option -M:

-M Instead of outputting the result of preprocessing, output a rule suitable for make describing the dependencies of the main source file. The preprocessor outputs one make rule containing the object file name for that source file, a colon, and the names of all the included files, including those coming from -include or -imacros command line options.

If you do, gcc -M filename.c, it'll list out all headers. Same with g++.

Upvotes: 10

Related Questions