如何让 g++ 列出所有#included 文件的路径 [英] How To Get g++ to list paths to all #included files

查看:41
本文介绍了如何让 g++ 列出所有#included 文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让 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.

来自手册:

不是输出预处理的结果,而是输出一条规则适合 make 描述主源文件的依赖关系.预处理器输出一个包含目标文件名的 make 规则对于该源文件,冒号和所有包含的名称文件,包括来自 -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++ 列出所有#included 文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆