每当我在我的项目中包含 D3DX11Effect.h
时,我会从多个不同的 DirectX
头文件中得到数百个错误,当我不包含 D3DX11Effect.h
。这些是我的包括:
#include <string>
#include <dwmapi.h>
#include <iostream>
#include <Windows.h>
#include <vector>
#include <thread>
#include <chrono>
#include <string>
#include <sstream>
#include <TlHelp32.h>
#include <exception>
#include <memory>
#include <vector>
#include <D3D11.h>
#include <d3dx11.h>
#include <DXErr.h>
#include <D3DX11async.h>
#include <D3DX11Effect.h>
#include <D3Dcompiler.h>
#include <D3D11Shader.h>
#include <FW1FontWrapper.h>
#include "../Drawing/ImGUI/imgui.h"
#include "../Drawing/DirectX.h"
#include "../Drawing/imgui_dx11.h"
#include "../Drawing/ShaderFX.h"
#include "../Drawing/Renderer.h"
#include "Global.h"
我正在使用 Direct X 11
和Windows SDK 版本 10.0.16299.0
。我试过重新安装 DirectX
但没有成功。这是我遇到的一些错误的图片:
感谢任何帮助。
最佳答案
长话短说:阅读MSDN .
DirectX SDK 已弃用,Windows 8.0 SDK、Windows 8.1 SDK 和 Windows 10 SDK header 比旧版 DirectX SDK 中提供的 header 更新。您得到的是旧 header 和新 header 的混合,这就是您收到这些错误的原因。
首先要考虑的是您是否需要使用旧版 DirectX SDK。理想情况下,您只是不使用它。这意味着避免使用 D3DX11
实用程序库,它本身也已被弃用。您可以找到文章 Living without D3DX 中列出的该功能的许多开源替代品,包括最新版本的Effects for Dirct3D 11 .
您可以继续混合使用旧版 DirectX SDK 和现代版本的 Windows SDK,但您需要谨慎操作,如 MSDN 页面底部所述 Where is the DirectX SDK? :
- VC++ 目录 include/lib 路径必须采用相反传统顺序,以便您在冲突的地方获得较新的 header
- 您需要在包含
d3dx11.h
之前显式包含d3d11.h
和dxgi.h
或者你最终得到了错误的版本——这正是上面发生的事情;您使用的是dxgi
和/或d3dcommon
的过时版本。 - 对于
dxerr.h
,按照说明构建您自己的版本 here因为 (a) 它不包含在 Windows SDK 中,并且 (b) 旧版 DirectX SDK 中包含的版本与现代版本的 Visual C++ 不完全兼容。
Note that the error buried in your image:
C2440 static_cast cannot convert from const char[6] to char *
inrenderer.h
has nothing to do with the issue above. This is due to the fact that modern C++11 rules on string literals disallow using them as non-const. You should fix the code, but you can also turn off strictstrings if you don't care about portability/conformance. In any case, take some time to read up on const correctness.
参见 The Zombie DirectX SDK完整剖析哪些 header 冲突,哪些是 DirectX SDK 独有的,哪些对现代 Windows 版本上的 DirectX 11 游戏有任何值(value)。
你应该回顾一下我在过去 8 年里在 this subject 上发表的各种帖子。
关于c++ - 包含 "D3DX11Effect.h"时出现数百个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48490236/