Displaying the #include hierarchy for a C++ file i

2019-01-02 17:12发布

Problem: I have a large Visual C++ project that I'm trying to migrate to Visual Studio 2010. It's a huge mix of stuff from various sources and of various ages. I'm getting problems because something is including both winsock.h and winsock2.h.

Question: What tools and techniques are there for displaying the #include hierarchy for a Visual Studio C++ source file?

I know about cl /P for getting the preprocessor output, but that doesn't clearly show which file includes which other files (and in this case the /P output is 376,932 lines long 8-)

In a perfect world I'd like a hierarchical display of which files include which other files, along with line numbers so I can jump into the sources:

source.cpp(1)
  windows.h(100)
    winsock.h
  some_other_thing.h(1234)
    winsock2.h

8条回答
美炸的是我
2楼-- · 2019-01-02 17:38

There is a setting:

Project Settings -> Configuration Properties -> C/C++ -> Advanced -> Show Includes

that will generate the tree. It maps to the compiler switch /showIncludes

查看更多
泪湿衣
3楼-- · 2019-01-02 17:38

Here is a good 3rd-party, FOSS tool. You can export results to XML, which will include data on number of occurrences and line numbers.

查看更多
像晚风撩人
4楼-- · 2019-01-02 17:40

We have found IncludeManager to be a very powerful tool. It is not free (but not expensive) and it allowed us to get a grip of our Include issues and drop our compile time from 50 minutes to 8 minutes by pruning out large chunks of includes we weren't using.

查看更多
怪性笑人.
6楼-- · 2019-01-02 17:50

The compiler also supports a /showIncludes switch -- it doesn't give you line numbers, but can give a pretty comprehensive view of which includes come from where.

It's under Project Settings -> Configuration Properties -> C/C++ -> Advanced -> Show Includes.

查看更多
余生请多指教
7楼-- · 2019-01-02 17:53

There is now a plugin for Visual Studio called IncludeToolbox. It can list your dependent includes and do more things like a random remove and compile to see if that include was required.

查看更多
登录 后发表回答