您知道项目文件中包含文件的工具构建树吗?

2022-01-04 00:00:00 include scripting c++

说,我想要一个工具(或脚本?)获取项目(或 .h 文件)并构建包含在其中的包含"的可搜索树(包含到包含到等等).有没有这样的东西?我应该自己写这个吗[当然我是:),但可能有人已经写好了,或者可能知道如何得到它]?

Say, I'd like to have a tool (or script?) taking project (or .h file) and building searchable tree of "includes" included into it (of included into of included into and so so on). Is there exist something like this? Should I write this by myself [of course I am :), but may be somebody had it already written or may be has an idea how to get it]?

推荐答案

不完全确定这是您想要的,但是您可以通过从基础 c 生成后 CPP 处理的文件轻松获得包含列表文件,并 grepping 出文件/行号注释,例如,使用 gcc

Not entirely sure this is what you're after, but you can easily get a list of includes by generating the post-CPP-processed file from the base c file, and grepping out the file/line number comments, e.g., using gcc

gcc -E main.c {usual flags} | grep '#' | cut -d' ' -f3 | sort | uniq

其中 main.c 是您的基本 c 文件.

where main.c is your base c file.

相关文章