Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Error in Linker - Error LNK2019

$
0
0
Hey there,

I am having a error when trying to build a Win32 Desktop application in VS 2012

here is the code:-
#include <Windows.h>
#include <d3d11_1.h>

static TCHAR szWindowClass[] = L"DX11_Win32 Application";
static TCHAR szWindowTitle[] = L"DirectX 11 Test";

IDXGISwapChain *swapChain;
ID3D11Device *device;
ID3D11DeviceContext *deviceContext;

void InitD3D(HWND hWnd);
void ClearD3D(void);

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = hInst;
	wcex.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_WINLOGO));
	wcex.hCursor = LoadCursor(hInst, MAKEINTRESOURCE(IDC_HAND));
	wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW +16);
	wcex.lpszMenuName = NULL;
	wcex.lpszClassName = szWindowClass;
	wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));

	if(!RegisterClassEx(&wcex))
	{
		MessageBox(NULL, L"Call to RegisterClassEx Failed!", L"Win32 DX11", NULL);
		return 1;
	}

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

	HWND hWnd = CreateWindow(
		szWindowClass,
		szWindowTitle,
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		wr.left - wr.right,
		wr.top - wr.bottom,
		NULL,
		NULL,
		hInst,
		NULL);

	if(!hWnd)
	{
		MessageBox(NULL, L"Call to CreateWindow failed", L"Error!", NULL);
		return 1;
	}

	ShowWindow(hWnd, nCmdShow);
	InitD3D(hWnd);

	MSG msg;

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

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

	ClearD3D();

	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_DESTROY:
		{
			PostQuitMessage(0);
			return 0;
		}
		break;
	default:
		DefWindowProc(hWnd, message, wParam, lParam);
		break;
	}
}

void InitD3D(HWND hWnd)
{
	DXGI_SWAP_CHAIN_DESC scd;

	ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

	scd.BufferCount = 1;
	scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	scd.OutputWindow = hWnd;
	scd.SampleDesc.Count = 8;
	scd.Windowed = TRUE;

	D3D11CreateDeviceAndSwapChain(NULL,
		D3D_DRIVER_TYPE_HARDWARE,
		NULL,
		NULL,
		NULL,
		NULL,
		D3D11_SDK_VERSION,
		&scd,
		&swapChain,
		&device,
		NULL,
		&deviceContext);
}

void ClearD3D()
{
	swapChain->Release();
	device->Release();
	deviceContext->Release();
}




Errors:-
1>------ Build started: Project: D3D_engine, Configuration: Debug Win32 ------
1>Build started 12/15/2012 2:06:35 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\D3D_engine.unsuccessfulbuild".
1>ClCompile:
1>  All outputs are up-to-date.
1>Engine.obj : error LNK2019: unresolved external symbol _D3D11CreateDeviceAndSwapChain@48 referenced in function "void __cdecl InitD3D(struct HWND__ *)" (?InitD3D@@YAXPAUHWND__@@@Z)
1>c:\users\arunabh\documents\visual studio 2012\Projects\D3D_engine\Debug\D3D_engine.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.46
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Waiting for help, Thanks
Arunabh

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>