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

前端 未结 2 885
夕颜
夕颜 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:28

    You need to invoke g++ with the -M option.

    From the manual:

    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.

    It's worth reading the manual to consider the other -M sub options (-MM and -MF in particular may be of use).

提交回复
热议问题