Possible Duplicates:
C/C++: Detecting superfluous #includes? How should I detect unnecessary #include files in a large C++ project?
I'm looking to do some house cleaning in our code base. I would like to start by removing all unnecessary header includes from our source files (*.c and *.cpp). Does anyone know of a tool or tec开发者_如何学Gohnique for doing this?
We are using GCC on Mac, Linux and Solaris. Using Visual Studio on Windows. I looked through the documentation of both compilers and there did not seem to be a option to make it warn for unnecessary includes.
Any thoughts or advice are appreciated.
I had to do this once and I ended up doing this:
- I removed almost every
#include
statements from both my haeder and source files - I tried to compile my source code
Whenever the compiler complains about something undefined, I either:
- Added a minimal declaration instead of a header inclusion wherever I could (something like: "class SomeClass;" instead of `#include "someclass.hpp")
- Added the required include when I had no other choice.
Go to 2. until it succeeds.
I admit this is long and boring, but it worthed it.
精彩评论