3

Possible Duplicates:
C/C++: Detecting superfluous #includes?
How should I detect unnecessary #include files in a large C++ project?

Hi,

I've been following numerous discussions about how to reduce the build time for C/C++ projects. Usually, a good optimization is to get rid of #include statements by using forward declarations. Now, I was wondering:

Is there maybe a tool which can compute the #include dependency tree between C/C++ header files (I know mkdep on Linux can do this) and then starts a 'remove header file/recompile' cycle? It would be great if the tool could try to remove nodes from the dependency tree (e.g. remove #include statments from files) and then rebuild the project to see whether it still works.

It shouldn't need to be very clever (as in, refactoring the code to make header files unnecessary by using pointers instead of values or the like) but I believe many projects I worked on had plain unneeded #include statements. This usually happens by refactoring code and moving it around, but then forgetting to take the #include out.

Does anybody know whether a tool like this exists?

Community
  • 1
  • 1
Frerich Raabe
  • 81,733
  • 18
  • 105
  • 196
  • 2
    possible duplicates: http://stackoverflow.com/questions/614794/c-c-detecting-superfluous-includes and http://stackoverflow.com/questions/74326/how-should-i-detect-unnecessary-include-files-in-a-large-c-project – dfa Jul 24 '09 at 09:32
  • Note that when you have to build for multiple configurations (either platforms or build options), the problem becomes more complicated as you don't want to break other builds. Another thing is that your goal of automatically minimizing dependencies may interfere with another goal: keeping each include file self-sufficient. – AProgrammer Jul 24 '09 at 09:56
  • build box(es) being x86_64 with 8Gb+ of RAM, fast multicore CPUs with biggest L1/L2 caches that you can get, would be a brute-force but quick and cheap approach to the build time optimization problem. Can tell that from personal experience with a sizable codebase :-) Besides, it's only the first build that takes a lot of time - if you are doing incremental changes, you should need to only recompile very few modules, so worth looking at the problem also from another angle. – Andrew Y Jul 24 '09 at 11:38

1 Answers1

2

There have been lots of questions here similar to this. So far, no-one has come up with a really good tool to list the dependancy graph and hilight multiple includes etc. (favourite seems to be doxygen) much less perform edits on the files themselves. So I would guess the anser is going to be "No" - I'd be happy to be wrong, however!