简体   繁体   中英

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.

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++.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM