Sign in to follow this  

error LNK2019: unresolved external symbol

This topic is 1529 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The full error message is this:

Error 2 error LNK2019: unresolved external symbol "bool __cdecl InitializeD3DApp(struct HINSTANCE__ *)" (?InitializeD3DApp@@YA_NPAUHINSTANCE__@@@Z) referenced in function _WinMain@16

and

Error 3 error LNK2019: unresolved external symbol _D3D10CreateDeviceAndSwapChain@32 referenced in function "bool __cdecl InitializeD3DDevice(struct HINSTANCE__ *)" (?InitializeD3DDevice@@YA_NPAUHINSTANCE__@@@Z) C:\Users\Tony\Desktop\C++ DX Apps\Test\Test\main.obj

 

Now, let me start by saying that I've done a solid amount of research on this, and the problem usually results in not linking the D3D10.lib library. I, however have done that and I still get this error. I've been able to get rid of the second error by including the x86 library (in the VC++ Directories) instead of the x64 (I am running a 64 bit CPU), but the first one still exists. So, why else could I be getting this error?
 

Here is the full code:
 

main.h:

#ifndef _MAIN_H_
#define _MAIN_H_

// LINKING /////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma comment(lib, "d3d10.lib")
#pragma comment(lib, "d3dx10.lib")
#pragma comment(lib, "dxgi.lib")

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// INCLUDES ////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <Windows.h>
#include <WindowsX.h>
#include <d3d10.h>
#include <d3dx10.h>

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// DEFINITIONS /////////////////////////////////////////////////////////////////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// FUNCTION PROTOTYPES /////////////////////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
bool InitializeWindow(HINSTANCE hInstance, int showWnd, int wndWidth, int wndHeight, bool windowed, 
						LPCWSTR& outErrorTitle, LPCWSTR& outErrorText, UINT& outUType);
int MessageLoop();

bool InitializeD3DApp(HINSTANCE hInstance);
bool InitScene();
void DrawScene();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// GLOBAL VARIABLES ////////////////////////////////////////////////////////////////////////////////////////////////////
HWND m_hwnd = NULL;
LPCWSTR m_wndClassName = L"WindowClass1";

const int m_windowWidth  = 800;
const int m_windowHeight = 600;

// Message Box Error Params
LPCWSTR m_errorTitle, m_errorText;
UINT m_uType;

ID3D10Device* m_d3dDevice;
IDXGISwapChain* m_swapChain;
ID3D10RenderTargetView* m_renderTargetView;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


#endif // _MAIN_H_

main.cpp:

#include "main.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	if (!InitializeWindow(hInstance, nCmdShow, m_windowWidth, m_windowHeight, true, m_errorTitle, m_errorText, m_uType))
	{
		MessageBox(m_hwnd, m_errorText, m_errorTitle, m_uType);
		return 0;
	}

	if (!InitializeD3DApp(hInstance))
	{
		MessageBox(m_hwnd, L"Could not initialize D3D device", L"Error", MB_OK | MB_ICONERROR);
		return 0;
	}

	if (!InitScene())
	{
		MessageBox(m_hwnd, L"Could not initialize scene", L"Error", MB_OK | MB_ICONERROR);
		return 0;
	}

	MessageLoop();

	return 0;
}

bool InitializeWindow(HINSTANCE hInstance, int showWnd, int wndWidth, int wndHeight, bool windowed, 
						LPCWSTR& outErrorTitle, LPCWSTR& outErrorText, UINT& outUType)
{
	WNDCLASSEX wc;
	ZeroMemory(&wc, sizeof(WNDCLASSEX));

	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
	wc.lpszMenuName = NULL;
	wc.lpszClassName = m_wndClassName;
	wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

	if (!RegisterClassEx(&wc))
	{
		outErrorTitle = L"Error";
		outErrorText  = L"Could not register class";
		outUType      = MB_OK | MB_ICONERROR;
		return false;
	}

	m_hwnd = CreateWindowEx(NULL, m_wndClassName, L"Window Title", WS_OVERLAPPEDWINDOW, 0, 0, wndWidth, wndHeight, NULL, NULL, hInstance, NULL);
	if (!m_hwnd)
	{
		outErrorTitle = L"Error";
		outErrorText  = L"Could not create window";
		outUType      = MB_OK | MB_ICONERROR;
	}

	ShowWindow(m_hwnd, showWnd);
	UpdateWindow(m_hwnd);

	return true;
}

int MessageLoop()
{
	MSG msg;
	ZeroMemory(&msg, sizeof(MSG));

	while (true)
	{
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

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

	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_KEYDOWN:
		if (wParam == VK_ESCAPE)
		{
			if (MessageBox(NULL, L"Are you sure you would like to exit?", L"Exit", MB_YESNO | MB_ICONQUESTION) == IDYES)
				DestroyWindow(hwnd);
			return 0;
		}
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}

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

bool InitializeD3DDevice(HINSTANCE hInstance)
{
	DXGI_SWAP_CHAIN_DESC swapChainDesc;
	ID3D10Texture2D* backBuffer;
	D3D10_VIEWPORT viewport;

	ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
	swapChainDesc.BufferDesc.Width = m_windowWidth;
	swapChainDesc.BufferDesc.Height = m_windowHeight;
	swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
	swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
	swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
	swapChainDesc.SampleDesc.Count = 1;
	swapChainDesc.SampleDesc.Quality = 0;
	swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapChainDesc.BufferCount = 1;
	swapChainDesc.OutputWindow = m_hwnd;
	swapChainDesc.Windowed = true;
	swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
	swapChainDesc.Flags = 0;

	D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_d3dDevice);

	m_swapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)(&backBuffer));

	m_d3dDevice->CreateRenderTargetView(backBuffer, 0, &m_renderTargetView);
	backBuffer->Release();

	m_d3dDevice->OMSetRenderTargets(1, &m_renderTargetView, NULL);

	viewport.Width = m_windowWidth;
	viewport.Height = m_windowHeight;
	viewport.TopLeftX = 0;
	viewport.TopLeftY = 0;
	viewport.MinDepth = 0.1f;
	viewport.MaxDepth = 100.0f;

	m_d3dDevice->RSSetViewports(1, &viewport);
	
	return true;
}

bool InitScene()
{
	return true;
}

void DrawScene()
{
	m_d3dDevice->ClearRenderTargetView(m_renderTargetView, D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f));
	m_swapChain->Present(0, 0);
}


Share this post


Link to post
Share on other sites

There is no InitializeD3DApp function in your post, so the linker is complaining that it's missing, when WinMain is trying to call it.

Is the InitializeD3DDevice function meant to be named InitializeD3DApp?

Edited by Hodgman

Share this post


Link to post
Share on other sites

I spent like two days trying to figure this out. I am very upset. Thank you hodgman

Share this post


Link to post
Share on other sites
Sign in to follow this