Tool to analyze header dependencies & eliminate redundancy

C

Code4u

We have a mature project that suffers long build times because many
modules pull in far more than they need. In the long term I would like
to refactor to break some of the dependencies, but I would like to
start by eliminating unneeded header includes. Is there a tool that
can parse a set of source files and identify redundancies?
 
J

Jack Klein

We have a mature project that suffers long build times because many
modules pull in far more than they need. In the long term I would like
to refactor to break some of the dependencies, but I would like to
start by eliminating unneeded header includes. Is there a tool that
can parse a set of source files and identify redundancies?

Redundancies should be limited by include guards, or perhaps
implementation-specific options that some provide that prevent even
opening the file a second time to get to the header guard.

As for a tool that detects unnecessary inclusions, PC-Lint
(www.gimpel.com) does an excellent job of that in C code. They claim
to do so in C++ as well, but I haven't verified that as extensively as
I have with C.
 
M

Mercator

Code4u said:
We have a mature project that suffers long build times because many
modules pull in far more than they need.

Most large C++ projects make that mistake.
In the long term I would like
to refactor to break some of the dependencies, but I would like to
start by eliminating unneeded header includes. Is there a tool that
can parse a set of source files and identify redundancies?

g++ has a compiler switch that prints all included files of a given
source file. 'makedepend' also finds out include dependencies. You can
analyze the output with a hand-written tool.
AFAIK, no tool is available that tells you which #includes can be
changed to forward declarations. BTW, before you start you need to read
Lakos 'Large-Scale C++ Software Design'.
 
S

Stuart MacMartin

Also check if your project supports precompiled headers.

grep for #include within your .h files

Create a dependency file (makedepends or if Visual Studio export
makefile with dependencies). Scan this manually or with a script to
find heavily used include files.

Stuart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top