1 Replies - 5731 Views - Last Post: 28 September 2010 - 02:53 AM Rate Topic: -----

#1 Somyagupta  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 85
  • Joined: 05-August 10

Linker error

Posted 27 September 2010 - 08:17 PM

Hi,

I am trying to learn a bit of game programming concepts. While following an online tutorail I created a window creation function in Visual studio 2010. The code is as follows
#include <windows.h>
#include <windowsx.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dx10.h>

// include the Direct3D Library file
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "d3dx11.lib")
#pragma comment (lib, "d3dx10.lib")

// global declarations
IDXGISwapChain *swapchain;             // the pointer to the swap chain interface
ID3D11Device *dev;                     // the pointer to our Direct3D device interface
ID3D11DeviceContext *devcon;           // the pointer to our Direct3D device context

// function prototypes
void InitD3D(HWND hWnd);    // sets up and initializes Direct3D
void CleanD3D(void);        // closes Direct3D and releases memory

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    HWND hWnd;
    WNDCLASSEX wc;

    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = "WindowClass";

    RegisterClassEx(&wc);

    RECT wr = {0, 0, 800, 600};
    AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);

    hWnd = CreateWindowEx(NULL,
                          "WindowClass",
                          "Our First Direct3D Program",
                          WS_OVERLAPPEDWINDOW,
                          300,
                          300,
                          wr.right - wr.left,
                          wr.bottom - wr.top,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hWnd, nCmdShow);

    // set up and initialize Direct3D
    InitD3D(hWnd);

    // enter the main loop:

    MSG msg;

    while(TRUE)
    {
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);

            if(msg.message == WM_QUIT)
                break;
        }
        else
        {
            // Run game code here
            // ...
            // ...
        }
    }

    // clean up DirectX and COM
    CleanD3D();

    return msg.wParam;
}


// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_DESTROY:
            {
                PostQuitMessage(0);
                return 0;
            } break;
    }

    return DefWindowProc (hWnd, message, wParam, lParam);
}


// this function initializes and prepares Direct3D for use
void InitD3D(HWND hWnd)
{
    // create a struct to hold information about the swap chain
    DXGI_SWAP_CHAIN_DESC scd;

    // clear out the struct for use
    ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

    // fill the swap chain description struct
    scd.BufferCount = 1;                                    // one back buffer
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;     // use 32-bit color
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;      // how swap chain is to be used
    scd.OutputWindow = hWnd;                                // the window to be used
    scd.SampleDesc.Count = 4;                               // how many multisamples
    scd.Windowed = TRUE;                                    // windowed/full-screen mode

    // create a device, device context and swap chain using the information in the scd struct
    D3D11CreateDeviceAndSwapChain(NULL,
                                  D3D_DRIVER_TYPE_HARDWARE,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  D3D11_SDK_VERSION,
                                  &scd,
                                  &swapchain,
                                  &dev,
                                  NULL,
                                  &devcon);
}


// this is the function that cleans up Direct3D and COM
void CleanD3D(void)
{
    // close and release all existing COM objects
    swapchain->Release();
    dev->Release();
    devcon->Release();
} 




When I try to build the code I get the following error:
Error 1 error LNK1104: cannot open file 'd3dx11.lib' C:\Somya\Coding\directx\Sample\Sample\LINK Sample

Can someone please help me solve this error. Note that I am including the include file in this project.


Thanks

This post has been edited by Somyagupta: 27 September 2010 - 08:18 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Linker error

#2 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 999
  • View blog
  • Posts: 4,177
  • Joined: 14-February 08

Re: Linker error

Posted 28 September 2010 - 02:53 AM

For this you are going to have to tell Visual Studio where your DirectX files are located on your computer. To do this you can right click on your project in the solution explorer and choose

Properties -> VC++ Directories -> Click the drop down arrow to the right and then click edit, add the path to your directX sdk bin x86 folder, mine looks like this C:\Program Files\Microsoft DirectX SDK (February 2010)\Utilities\Bin\x86

do the same for the include part, adding your own version of this folder
C:\Program Files\Microsoft DirectX SDK (February 2010)\Include

And again for Libraries
C:\Program Files\Microsoft DirectX SDK (February 2010)\Lib\x86

And then source files
C:\Program Files\Microsoft DirectX SDK (February 2010)\Utilities\Source

This will work for your current project but if you want it to work for all projects you will have to edit the property manager, go to Tools -> Settings -> and check Expert Settings

Now you can go to View -> Property Manager -> and then edit the debug and release versions of Microsoft.Cpp.Win32.User in the same way you edited the previous fields.

I hope that explained things just ask if you need more help :)
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1