分析/清理#include依赖项的工具? [英] tool to analyze/cleanup #include dependencies?

查看:223
本文介绍了分析/清理#include依赖项的工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以推荐一种工具来分析和清除实际上不需要的大量源/头文件中多余的#include语句吗?它需要能够智能分析文件并找出需要使用哪些#include语句来删除实际上不必要的多余内容的东西.

目的是避免由实际上不需要的#include语句触发不必要的重新编译.也就是说,您更改了标头,并重新构建了包含标头的所有内容,但是实际上并不需要这样做,而是包含了许多包含标头的东西.

Can anyone recommend a tool for analyzing and cleaning up excess #include statements throughout a large number of source/header files which aren''t actually needed? It would need to be something that could intelligently analyze the files and figure out which #include statements ARE needed to allow removing the excess ones which aren''t actually necessary.

The goal is to avoid unnecessary re-compilation triggered by #include statements which aren''t actually needed. i.e. you change a header and everything which #include''s that header is rebuilt, but a lot of stuff that #include''s it doesn''t actually need to do so.

推荐答案

我认为PC-Lint可能可以解决这个问题,我很确定我已经看到它警告未使用的头文件-目前还没有安装它,因此无法检查.
I think that PC-Lint might be able to help with this, I''m pretty sure I''ve seen it warn about unused headers - I don''t have it installed at the moment so can''t check.


Doxygen可以用于此...它可以构建依赖关系图.

还有一些技巧可以用来手工进行清理.

1)选择一个有问题的文件,然后在其中添加#pragma error Is it used.然后编译该项目.包含该文件的任何文件都不会编译.然后,您可以分析这些内容以查看是否需要包含这些内容.

2)注释掉头文件的某些部分,然后查看它是否仍在编译.您也许可以拆分一个文件,以使正在更改的定义与例如很少更改的复杂声明不在同一个文件中.
Doxygen can be used for that... It can build dependency graphes.

And there a few tricks that can be used to do some cleanup by hand.

1) Select a problematic file and add a #pragma error Is it used in it. Then compile that project. Any file that include that won''t compile. Then you can analyse those to see if included are needed or not.

2) Comment out some portion of an header file and see if it still compile. You might be able to split a file so that definition that are changing a lot are not in the same file as complex declaration that seldom changes for example.


前段时间,我遇到了类似的问题问题,花了两天的时间来手动"解决,方法是从头文件中取出所有#includes并将它们插入任何停止编译的cpp文件中.只有例外是基类的#includes,还有一些由于外部依赖而无法轻易移动的例外.仅此一项就将编译时间增加了2-3倍!

后来我发现了一个可能有用的产品: IncludeManager .我还没有花时间测试它,但是由于它提供了免费试用,您不妨尝试一下.我希望它的图形能给您一个很好的主意,在哪里优化可以带来最大收益.
Some time ago I was faced with similar problems and spent two days solving it ''manually'' by taking all the #includes out of the header files and inserting them in any cpp file that stopped compiling. Only exceptions were #includes to base classes and a few exceptions that I couldn''t easily move because of external dependencies. That alone increased compile times by a factor of 2-3!

Later I''ve found a product that might have been helpful: IncludeManager. I didn''t yet take the time to test it, but since it offers a free trial you might just as well give it a try. I''d expect that it''s graphs give you a good idea where optimization might pay off most.


这篇关于分析/清理#include依赖项的工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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