Daniel Petersen
Daniel Petersen

Reputation: 48

Calling D3DReadFileToBlob in Visual Studio 2012 causes link error

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.

#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.

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.

Upvotes: 0

Views: 2124

Answers (3)

Mi Po
Mi Po

Reputation: 1203

So you can't include d3dx11.lib anymore if using Windows Kit, but you can include the d3dcompiler.lib which you can find (typically) in C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64 or whatever build you are using,

Upvotes: 1

Chuck Walbourn
Chuck Walbourn

Reputation: 41057

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.

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.

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

Upvotes: 1

alanw
alanw

Reputation: 665

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.

Upvotes: 0

Related Questions