Most approaches for removing unused includes work better if you first make sure that each your header files compiles on its own. I did this relatively quickly as follows (apologies for typos -- I am typing this at home:
find . -name '*.h' -exec makeIncluder.sh {} \;
where makeIncluder.sh
contains:
#!/bin/sh
echo "#include \"$1\"" > $1.cpp
For each file ./subdir/classname.h
, this approach creates a file called ./subdir/classname.h.cpp
containing the line
#include "./subdir/classname.h"
If your makefile
in the . directory compiles all cpp files and contains -I.
, then just recompiling will test that every include file can compile on its own. Compile in your favorite IDE with goto-error, and fix the errors.
When you're done, find . -name '*.h.cpp' -exec rm {} \;