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:54

Not as good as gcc's hierarchical include feature, which shows the direct-line inclusion hierarchy in the case of an error. The "show includes" option in VS shows everything, which is overkill when debugging hierarchical include file problems.

查看更多
爱死公子算了
3楼-- · 2019-01-02 17:58

cl /P should show you the line numbers, such that you can tell the context of where a header file is being included from.

If you grep out the lines with ...

grep "^#line" file.i

... then you should have a pretty clean indication of what files were encountered in order by the preprocessor.

If it's a one off incident this should be a pretty quick diagnostic.

查看更多
登录 后发表回答