Detecting superfluous #includes in C/C++?(在 C/C++ 中检测多余的#include?)
问题描述
我经常发现文件的标题部分一直在变大,但从未变小.在源文件的整个生命周期中,类可能已经移动和重构,并且很可能有很多 #includes
不再需要存在.将它们留在那里只会延长编译时间并添加不必要的编译依赖项.试图找出仍然需要哪些可能非常乏味.
I often find that the headers section of a file get larger and larger all the time but it never gets smaller. Throughout the life of a source file classes may have moved and been refactored and it's very possible that there are quite a few #includes
that don't need to be there and anymore. Leaving them there only prolong the compile time and adds unnecessary compilation dependencies. Trying to figure out which are still needed can be quite tedious.
是否有某种工具可以检测多余的#include 指令并建议我可以安全删除哪些指令?
lint 可能会这样做吗?
Is there some kind of tool that can detect superfluous #include directives and suggest which ones I can safely remove?
Does lint do this maybe?
推荐答案
不是自动的,而是doxygen将为 #included
文件生成依赖关系图.您将不得不直观地浏览它们,但它们对于了解什么使用什么非常有用.
It's not automatic, but doxygen will produce dependency diagrams for #included
files. You will have to go through them visually, but they can be very useful for getting a picture of what is using what.
这篇关于在 C/C++ 中检测多余的#include?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C/C++ 中检测多余的#include?
基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01