views:

462

answers:

6

I have a very large project with tons of convoluted header files that all include each other. There's also a massive number of third-party libraries that it depends on. I'm trying to straighten out the mess, but I'm having some trouble, since a lot of the time I'll remove one #include directive only to find that the stuff it was including is still included through one of the other files. Is there any tool that can help me understand this? I'd really like to be able to click on a .h file and ask it which CPP files it's included in (directly or indirectly), and the paths through which it is included, and likewise click a cpp file and ask it which .h files are included (directly and indirectly). I've never heard of a tool that does this, and a bit of quick googling hasn't turned anything up, but maybe I don't know what to search for.

+3  A: 

if you use GCC compilers, try this

g++ -M abc.cpp

it will show all include dependencies for the file abc.cpp

oykuo
I'm using Visual Studio 2008.
rmeador
+3  A: 

For VS2003 there is /showIncludes flag (in C/C++/Advanced properties). This will print all headers each .cpp file includes and what they include, so you can go from there.

I'm sure there is same option in same place for VS2008.

Eugene
this does exist for VS2008, in the same place. it looks very promising. it also tells me my task is far more daunting than I had assumed...
rmeador
A: 

Your situation reminds me of my own. I have a bunch of headers that I have created that I use as a library instead of bothering with a DLL.

Of course the cyclic-includes can become troublesome, so I find that a tool like Visual Assist X (1) helps with this sort of thing. It has a function that can find references to stuff, so that you can easily weed out where something is being defined/declared/included etc. It also has a lot of other useful features, so I consider it to be pretty useful.

There’s probably other tools/plugins that have a referencing function, but usually as one feature among the other refactoring and productivity functions of the utility.

HTH

Synetech inc.
+3  A: 

http://www.profactor.co.uk/includemanager.php

Steve Folly
I feel somewhat bad about recommending a closed-source non-free tool, but this is by far the best answer to my question. It does pretty much everything I need, and it's not very expensive. My boss decided to buy licenses for most of the department.
rmeador
I'm just an impressed user! I haven't bought a licence yet and I've only used it during the trial period, but so far it's been very useful.
Steve Folly
A: 

It's pretty tedious, but you can binary-search your way to where an #include happens by using #error (and #pragma message) to narrow down which include line is pulling in the third party. I've done this in the case of a single file I was trying to track down, but it sounds like your problem is bigger so probably one of the tools others have mentioned would be more effective.

Chadwick