How To Get g++ to list paths to all #included files

前端 未结 2 894
夕颜
夕颜 2021-02-06 13:58

I would like to have g++/gcc tell me the paths to everything non-system it is #include-ing in C++ build. Turns out, that is a tough search as Google mus-interprets it about ten

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 14:26

    Try gcc or g++ with the -H option (to the preprocessor part of it). From the doc:

    -H

    Print the name of each header file used, in addition to other normal activities. Each name is indented to show how deep in the ‘#include’ stack it is. Precompiled header files are also printed, even if they are found to be invalid; an invalid precompiled header file is printed with ‘...x’ and a valid one with ‘...!’ .

    It tells you all the headers which are included. You may filter out (with grep -v or awk) those that you don't want.

    You could also consider developing your GCC plugin to register these headers somewhere (e.g. in your sqlite database), perhaps inspired by this draft report, or the CHARIOT or DECODER European projects. You could also consider using, or extending, the Clang static analyzer.

    In contrast to the -M options suggested in Oliver Matthews' answer, it does not tell you more (but gives all the included files).

提交回复
热议问题