CodeMode
CodeMode

Reputation: 55

error C3861: 'D3DCompileFromFile': identifier not found

I'm trying to use the D3D function D3DCompilFromFile and it was working completely fine until I tweaked my shader a bit and now all of a sudden my program has stopped recognizing the D3DCompileFromFile function, I have checked what header/libraries/dll's I need to include and they are all there to my knowledge.

I'm using VS2013

Here is some example code

application.cpp

HRESULT Application::CompileShaderFromFile(WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut)
{
    HRESULT hr = S_OK;

    DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined(DEBUG) || defined(_DEBUG)
    // Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif

    ID3DBlob* pErrorBlob;
    hr = D3DCompileFromFile(szFileName, nullptr, nullptr, szEntryPoint, szShaderModel,
        dwShaderFlags, 0, ppBlobOut, &pErrorBlob);

    if (FAILED(hr))
    {
        if (pErrorBlob != nullptr)
            OutputDebugStringA((char*)pErrorBlob->GetBufferPointer());

        if (pErrorBlob) pErrorBlob->Release();

        return hr;
    }

    if (pErrorBlob) pErrorBlob->Release();

    return S_OK;
}

application.h

#include <windows.h>
#include <d3d11_1.h>
#include <d3dcompiler.h>
#include <directxmath.h>
#include <directxcolors.h>
#include "resource.h"
#include <iostream>
#include <vector>
#include <time.h>
#include <stdio.h>
#include <stdlib.h> 

using namespace DirectX;
using namespace std;
.
.
.
.
HRESULT CompileShaderFromFile(WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut);

Lighting.fx

cbuffer cbData
{
    float4x4 World; 
    float4x4 View; 
    float4x4 Projection;

    float4 gDiffuseMtrl; 
    float4 gDiffuseLight; 
    float3 gLightVecW;
    float4 gAmbientMtrl;
    float4 gAmbientLight;
};

struct VS_IN
{
    float4 posL   : POSITION;
    float3 normalL : NORMAL;
};

struct VS_OUT
{
    float4 Pos    : SV_POSITION;
    float4 Col    : COLOR;
};

VS_OUT VS(VS_IN vIn)
{
    VS_OUT output = (VS_OUT)0;

    output.Pos = mul( vIn.posL, World ); 
    output.Pos = mul( output.Pos, View ); 
    output.Pos = mul( output.Pos, Projection );


    // Convert from local to world normal
    float3 normalW = mul(float4(vIn.normalL, 0.0f), World).xyz;
    normalW = normalize(normalW);

    // Compute Colour
    float s = max(dot(gLightVecW, normalW), 0.0f);
    float3 diffuse = s*(gDiffuseMtrl*gDiffuseLight).rgb;
    float3 ambient = gAmbientMtrl * gAmbientLight;
    output.Col.rgb = diffuse + ambient;
    output.Col.a = gDiffuseMtrl.a;


    return output;
}

float4 PS(VS_OUT pIn) : SV_Target
{
    return pIn.Col;
}

technique11 Render
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, PS() ) );
    }
}

Sorry if I'm just throwing way too much code at people but I'm really struggling to find out the cause of this

Upvotes: 1

Views: 6671

Answers (1)

Chuck Walbourn
Chuck Walbourn

Reputation: 41047

Are you using the legacy DirectX SDK? D3DCompileFromFile did not exist in the old #43 version of D3DCompiler which means you are probably picking up the older 'd3dcompiler.h' header in the DirectX SDK rather than the newer Windows 8.1 SDK version of 'd3dcompiler.h' which came with VS 2013.

Ideally you should not use the DirectX SDK at all (see Living without D3DX).

I see from your shader you are using Effects 11, so you should be sure to move to latest CodePlex version which doesn't need any DXSDK header. Be aware that the support for the 'fx_5_0' profile is deprecated and is expected to be removed in a future update of the HLSL compiler. The Windows 8.1 SDK #47 version of the compiler will emit a warning stating this, but will still compile these shaders.

Upvotes: 3

Related Questions