如何获取g ++列出所有包含的文件的路径 [英] How To Get g++ to list paths to all #included files
问题描述
我想让g ++/gcc告诉我通往所有非系统性路径的路径,它是C ++构建中的#include-ing.原来,这是一项艰巨的搜索,因为Google会以十种不同的方式解读它.
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 different ways.
我想要这些文件名和路径,以便将它们添加到Exuberant CTAGS的搜索路径中.我们有一个庞大的项目,如果我在整个过程中都使用ctags,则生成标记文件大约需要半小时,而编辑器进行查找所需的时间也差不多.
I want these filenames and paths so I can add them to the search path for Exuberant CTAGS. We have a huge project and if I use ctags on the whole thing it takes about half an hour to generate the tags file and nearly as long for the editor to do a look-up.
我们使用CMakeLisats进行编译.如果有指令,我可以将其粘贴到CMakeLists.txt中,那就太妙了.
We use CMakeLisats to do the compiling. If there is a directive I can paste into the CMakeLists.txt, that would be extra wonderfulness.
我真的不需要默认路径和文件名,Johnathan Wakely为此提供了一个很好的工具这里.我认为这几乎涵盖了一个交叉编译工作这一事实.我也不需要跨系统文件.
I don't really need the default paths and filenames, Johnathan Wakely gave a good tool for that here. I think that pretty much covers the fact that this is a cross compile job. I don't need the cross-system files either.
推荐答案
您需要使用-M
选项调用g ++.
You need to invoke g++ with the -M
option.
手册:
输出规则,而不是输出预处理结果 适用于描述主源文件的依赖关系. 预处理器输出一个包含目标文件名的生成规则 对于该源文件,冒号以及所有包含的名称 文件,包括来自-include或-imacros命令行的文件 选项.
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.
值得阅读手册,以考虑其他-M
子选项(尤其是-MM
和-MF
可能有用).
It's worth reading the manual to consider the other -M
sub options (-MM
and -MF
in particular may be of use).
这篇关于如何获取g ++列出所有包含的文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!