Linker issue calling the D3DX10CreateEffectFromFile() method
Having issues trying to retrieve a effect file for directX. If I do not include the D3DX10CreateEffectFromFile() method, the application compiles correctly. If I do include it. I get the following error
1>GXDX.obj : error LNK2019: unresolved external symbol _D3DX10CreateEffectFromFileW@48 referenced in function "public: virtual void __thiscall GXDX::StartUp(struct HWND__ * *,int,int)" (?StartUp@GXDX@@UAEXPAPAUHWND__@@HH@Z)
1>C:\Users\numerical25\Desktop\Intro ToDirectX\GODFILES\GXRenderManager\GXRenderManager\Debug\GXRenderManager.exe : fatal error LNK1120: 1 unresolved externals
My first thought was maybe it is not linking the directx library correctly. But I find that to be off cause I am including the lib files and I am using other methods with no problem. below is my code.
header file
#ifndef GXDX_
#define GXDX_
#include "GXRenderer.h"
#include <d3d10.h>
#include <d3dx10.h>
#include "GXExceptions.h"
#pragma comment (lib, "d3d10.lib")
#pragma comment (lib, "d3dx10.lib")
class GXDX: public GXRenderer {
protected:
ID3D10Device* gm_dxDevice;
IDXGISwapChain* gm_swapChain;
ID3D10RenderTargetView* gm_renderTargetView;开发者_StackOverflow社区
ID3D10Effect *gm_shader;
ID3D10EffectTechnique *gm_tech;
public:
void CleanUp();
void StartUp(HWND* window,int w, int h);
void SetupScene();
void DisplayScene();
void LoadMesh(GXVector*,UINT*);
void DrawText(LPSTR);
};
#endif
below is the implementation
void GXDX::StartUp(HWND* mainWindow,int w, int h)
{
width = w;
height = h;
this->m_mainWindow = mainWindow;
//Get size of window
RECT rectangle;
GetClientRect(*m_mainWindow,&rectangle);
ID3D10Texture2D *backBufferSurface;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
SecureZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
swapChainDesc.BufferCount = 2;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.OutputWindow = *mainWindow;
swapChainDesc.Windowed = TRUE;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
D3D10_DRIVER_TYPE driverType = D3D10_DRIVER_TYPE_HARDWARE;
HRESULT hr = D3D10CreateDeviceAndSwapChain(NULL,driverType,NULL,0,
D3D10_SDK_VERSION, &swapChainDesc,&gm_swapChain,&gm_dxDevice);
if(FAILED(hr))
throw GXVideoException(L"Problems retrieving directX device");
hr = gm_swapChain->GetBuffer(0,__uuidof(ID3D10Texture2D), (LPVOID*)&backBufferSurface);
if(FAILED(hr))
throw GXVideoException(L"Failure to retrieve buffer from swap chain");
hr = gm_dxDevice->CreateRenderTargetView(backBufferSurface, NULL,&gm_renderTargetView);
backBufferSurface->Release();
if(FAILED(hr))
throw GXVideoException(L"Failure to create Render Target View");
//In the future, you might want to change this to something that allows multiple views
//Like for an editor
gm_dxDevice->OMSetRenderTargets(1, &gm_renderTargetView, NULL);
UINT rectangle_width = rectangle.right - rectangle.left;
UINT rectangle_height = rectangle.bottom - rectangle.top;
D3D10_VIEWPORT viewport;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = rectangle_width;
viewport.Height = rectangle_height;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
//bind viewport
gm_dxDevice->RSSetViewports(1,&viewport);
D3D10_INPUT_ELEMENT_DESC layout[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA},
};
hr = D3DX10CreateEffectFromFile(L"shader.fx", NULL, NULL,
"fx_4_0",D3D10_SHADER_DEBUG,0,gm_dxDevice,NULL,NULL, &gm_shader,NULL,NULL);// Error here and dont know why
}
Gotta love linker errors. I mostly use DX9 at the moment, but I recall DX11 ditching effects (but still having them available). However, DX10 should still have them. Peeking through d3dx10async.h showed that the CompileEffectFromFile is still in there (June 2010 sdk), however. I noticed that the D3DX10CompileEffectFromFile is listed as deprecated in MSDN, with D3DX10CompileFromFile being its replacement. Double check your library links and try giving the D3DX10CompileFromFile function a shot (although theoretically if the CompileEffect func is still fully there and libraries are linked correctly it should work).
I guess the issue was that I didnt have the lib paths supplied in the additional lib directories under general in the solutions options area. I should of known that but it threw me off because any other method I called before this issue, worked fine.
精彩评论