在Visual Studio 2012中调用D3DReadFileToBlob会导致链接错误

时间:2021-06-18 10:06:49

I'm having a frustrating problem loading precompiled HLSL shaders in my DirectX project. I'm using Visual Studio 2012 Professional and DirectX SDK (June 2010). The code below is causing a link error of LNK2019: unresolved external symbol _D3DReadFileToBlob@8.

我在DirectX项目中加载预编译的HLSL着色器时遇到了令人沮丧的问题。我正在使用Visual Studio 2012 Professional和DirectX SDK(2010年6月)。下面的代码导致LNK2019的链接错误:未解析的外部符号_D3DReadFileToBlob @ 8。

#include "GameBase.h"
#include<D3Dcompiler.h>

bool GameBase::LoadShaderFromFile(LPCWSTR filePath, ID3DBlob** buffer)
{
    HRESULT result = D3DReadFileToBlob(filePath, buffer);

    if(FAILED(result))
    {
        return false;
    }

    return true;
}

The libraries d3d11.lib;d3dx11.lib;dxerr.lib;D3dcompiler.lib are set in the Linker > Input > Additional Dependencies, and the proper include directories and library directories are set for the DirectX SDK location: $(IncludePath);$(DXSDK_DIR)Include, and $(LibraryPath);$(DXSDK_DIR)Lib\x86) respectively.

库d3d11.lib; d3dx11.lib; dxerr.lib; D3dcompiler.lib在链接器>输入>附加依赖项中设置,并为DirectX SDK位置设置了正确的包含目录和库目录:$(IncludePath); $ (DXSDK_DIR)分别包含和$(LibraryPath); $(DXSDK_DIR)Lib \ x86)。

Removing this part of the code allows the rest of the project to compile and run without incident (With the obvious exception that the shaders don't load).

删除这部分代码允许项目的其余部分编译和运行而不会发生事故(明显的例外是着色器不加载)。

I feel I must be missing something subtle, but nothing I've found via search and Stack Overflow have yielded any insights into how to resolve this problem.

我觉得我必须遗漏一些微妙的东西,但我通过搜索和Stack Overflow找到的任何内容都没有提供任何有关如何解决此问题的见解。

2 个解决方案

#1


1  

Your problem is that you are mixing the Windows 8.x SDK and the DirectX SDK in such a way that you are using the older version of D3DCompile which doesn't support D3DReadFileToBlob.

您的问题是,您正在混合Windows 8.x SDK和DirectX SDK,使得您使用的旧版D3DCompile不支持D3DReadFileToBlob。

If using VS2012/Windows 8.0 SDK or the VS2013/Windows 8.1 SDK in combination with the legacy DirectX SDK, you need to modify the include/lib paths to get the 'correct' behavior. This is covered in detail on MSDN.

如果将VS2012 / Windows 8.0 SDK或VS2013 / Windows 8.1 SDK与旧版DirectX SDK结合使用,则需要修改include / lib路径以获得“正确”行为。这在MSDN上有详细介绍。

You should also read this blog entry about D3DCompile, DLL deployment, and versioning.

您还应该阅读有关D3DCompile,DLL部署和版本控制的博客文章。

#2


0  

Perhaps your mixing libraries with the windows 8 sdk which also has those libraries. Change your linking settings to see the included libraries and verify where d3dcompiler.lib is coming from, or if its linking to it at all.

也许你的混合库与windows 8 sdk也有这些库。更改链接设置以查看包含的库并验证d3dcompiler.lib的来源,或者是否链接到它。

#1


1  

Your problem is that you are mixing the Windows 8.x SDK and the DirectX SDK in such a way that you are using the older version of D3DCompile which doesn't support D3DReadFileToBlob.

您的问题是,您正在混合Windows 8.x SDK和DirectX SDK,使得您使用的旧版D3DCompile不支持D3DReadFileToBlob。

If using VS2012/Windows 8.0 SDK or the VS2013/Windows 8.1 SDK in combination with the legacy DirectX SDK, you need to modify the include/lib paths to get the 'correct' behavior. This is covered in detail on MSDN.

如果将VS2012 / Windows 8.0 SDK或VS2013 / Windows 8.1 SDK与旧版DirectX SDK结合使用,则需要修改include / lib路径以获得“正确”行为。这在MSDN上有详细介绍。

You should also read this blog entry about D3DCompile, DLL deployment, and versioning.

您还应该阅读有关D3DCompile,DLL部署和版本控制的博客文章。

#2


0  

Perhaps your mixing libraries with the windows 8 sdk which also has those libraries. Change your linking settings to see the included libraries and verify where d3dcompiler.lib is coming from, or if its linking to it at all.

也许你的混合库与windows 8 sdk也有这些库。更改链接设置以查看包含的库并验证d3dcompiler.lib的来源,或者是否链接到它。