【问题标题】:How to find which header is including another header in the include tree?如何在包含树中查找哪个标头包含另一个标头?
【发布时间】:2018-04-18 20:07:11
【问题描述】:

在来自 Microsoft DirectX 示例的 D3D12HelloWindow project 中,有对 IID_PPV_ARGS 的引用。当我在 VS2017 企业版中使用 F12 导航时,我到达了combaseapi.h,但是编译器的输出带有/showincludes 根本没有引用它。

最后,项目编译运行正常,但不知道哪个头文件直接包含或不直接包含combaseapi.h

如何找到正在使用combaseapi.h 的标头?

目标/问题是了解某个实现(某个 DirectX 12 方面),以便我可以使用它来丰富我自己的(在这种情况下是 DirectX 12 WPF 资产)。

【问题讨论】:

  • 是的,什么问题,什么时候项目编译运行?
  • @user463035818 问题不在于使示例运行,而在于了解其实现。阅读和理解代码是工程的重要组成部分。

标签: c++ visual-studio compilation


【解决方案1】:

我自己创建了一个非常小的示例。不行但是编译成功:

#include "stdafx.h"
#include "Objbase.h"
#include "Unknwn.h"
#include "Propsys.h"

int main()
{
    IPropertyStore *pPropertyStore;

    CoCreateInstance(IID_IUnknown, NULL, CLSCTX_INPROC_SERVER,
        IID_PPV_ARGS(&pPropertyStore));

    return 0;
}

在 Visual Studio 2017 中,我看到 combaseapi.h 包含在 Objbase.h 标头中:

1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um\Objbase.h
1>Note: including file:  C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\shared\winapifamily.h
1>Note: including file:   C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\shared\winpackagefamily.h
1>Note: including file:  C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\shared\rpc.h
...
1>Note: including file:    C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um\ole2.h
1>Note: including file:     C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\shared\pshpack8.h
1>Note: including file:     C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um\objbase.h
1>Note: including file:      C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\shared\pshpack8.h
1>Note: including file:      C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um\combaseapi.h
...

以上编译器输出应按以下方式读取。如果下面的行有更多缩进,则表示上行的标题包括下行的标题。我包括#include "Objbase.h" 并在我的.cpp 文件中并通过不断增加的缩进我看到combaseapi.h(输出附件中的最后一行)。由此我知道Objbase.h通过他的方式通过5个标题包括combaseapi.h

我使用的是 Windows 10。

Microsoft documentation看不到任何评论

也许尝试再次检查调试器输出?

【讨论】:

  • 好的,我想知道我通过哪个 .h 到达 combaseapi.h。是不是通过/showincludes 输出?
  • 你说“不是通过 /showincludes 输出是什么意思?” /showincludes 选项仅列出标题、它们的顺序以及哪个包含在哪个(缩进)中。
  • 我没有在 /showincludes 输出中看到 combaseapi.h。您是如何发现 Objbase.h 包含 combaseapi.h 的?
  • @Soleil 我已经更新了我的答案。现在清楚了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 2014-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多