c++ - 未解析的外部符号 _D3D10CreateDeviceAndSwapChain@32 在函数“public : bool 中引用

标签 c++ c visual-c++ directx

在创建我的交换链时遇到问题。我收到以下错误。

DX3dApp.obj : error LNK2019: unresolved external symbol _D3D10CreateDeviceAndSwapChain@32 referenced in function "public: bool __thiscall DX3dApp::InitDirect3D(void)" (?InitDirect3D@DX3dApp@@QAE_NXZ)

下面是我到目前为止完成的代码。

#include "DX3dApp.h"




bool DX3dApp::Init(HINSTANCE hInstance, int width, int height)
{
    mhInst = hInstance;
    mWidth = width;
    mHeight = height;

    if(!WindowsInit())
    {
        return false;
    }
    if(!InitDirect3D())
    {
        return false;
    }
}

int DX3dApp::Run()
{
     MSG msg = {0};

     while (WM_QUIT != msg.message)
    {
        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        Render();
    }

    return (int) msg.wParam;
}

bool DX3dApp::WindowsInit()
{
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = (WNDPROC)WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = mhInst;
    wcex.hIcon          = 0;
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = TEXT("DirectXExample");
    wcex.hIconSm        = 0;
    RegisterClassEx(&wcex);

    // Resize the window
    RECT rect = { 0, 0, mWidth, mHeight };
    AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);

    // create the window from the class above
    mMainhWnd = CreateWindow(TEXT("DirectXExample"), 
                             TEXT("DirectXExample"), 
                             WS_OVERLAPPEDWINDOW,
                             CW_USEDEFAULT, 
                             CW_USEDEFAULT, 
                             rect.right - rect.left, 
                             rect.bottom - rect.top, 
                             NULL, 
                             NULL, 
                             mhInst, 
                             NULL);
   if (!mMainhWnd)
   {
      return false;
   }

   ShowWindow(mMainhWnd, SW_SHOW);
   UpdateWindow(mMainhWnd);

   return true;
}

bool DX3dApp::InitDirect3D()
{
    DXGI_SWAP_CHAIN_DESC scd;
    ZeroMemory(&scd, sizeof(scd));

    scd.BufferCount = 1;
    scd.BufferDesc.Width = mWidth;
    scd.BufferDesc.Height = mHeight;
    scd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    scd.BufferDesc.RefreshRate.Numerator = 60;
    scd.BufferDesc.RefreshRate.Denominator = 1;
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    scd.OutputWindow = mMainhWnd;
    scd.SampleDesc.Count = 1;
    scd.SampleDesc.Quality = 0;
    scd.Windowed = TRUE;

    HRESULT hr = D3D10CreateDeviceAndSwapChain(NULL,D3D10_DRIVER_TYPE_REFERENCE,
                                                NULL,
                                                0,
                                                D3D10_SDK_VERSION,
                                                &scd,
                                                &mpSwapChain,
                                                &mpD3DDevice);

    if(!hr != S_OK)
    {
        return FALSE;
    }

    ID3D10Texture2D *pBackBuffer;

    return TRUE;
}

void DX3dApp::Render()
{

}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) 
    {
        // Allow the user to press the escape key to end the application
        case WM_KEYDOWN:
            switch(wParam)
            {
                // Check if the user hit the escape key
                case VK_ESCAPE:
                    PostQuitMessage(0);
                break;
            }
        break;

        // The user hit the close button, close the application
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}

最佳答案

您没有链接到 D3D 库 (D3D10.lib)。

将该库添加到您的链接器选项(项目属性 -> 链接器 -> 输入 -> 附加依赖项)。您还需要确保库位置位于“其他库目录”路径中。

关于c++ - 未解析的外部符号 _D3D10CreateDeviceAndSwapChain@32 在函数“public : bool 中引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2718284/

相关文章:

c++ - Qt - 在窗口上安装布局管理器

c++ - vector 删除功能删除错误的对象

c - 如何打印完整的 32 位值?

visual-c++ - 如何让 devenv.exe 在控制台上显示其输出

c++ - 如何调试 Visual C++ 9 中的缓冲区溢出?

c++ - 如何在栈和堆对象之间转换

c++ - 推导 C++11 中 lambda 参数的类型

c - 如何生成 16 位查找表来计算设置位

c - 在不同类型的变量之间分配共享内存时出现段错误

c++ - 将 C++11 std::thread 移植到 boost::thread 编译问题