Jump to content
  • Advertisement
Sign in to follow this  
Stefan Fischlschweiger

Unresolved External Symbol

This topic is 1133 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

So, I have a main exe and 2 dlls.

 

The exe contains a class (Metastorm) which is derived from another class (Game) contained in EngineBase.dll

The Game class contains a reference to a Renderer object, whose code lies in DX11Renderer.dll

 

Now, if I call renderer->Initialize(<args here>); in Metastorm the the linker throws me an LNK2019 error complaining that Renderer::Initialize is an unresolved external symbol.

 

but in Renderer.h I've put __declspec(dllexport) at the initialize function and in Game.h I wrote class __declspec(dllexport)

 

What am I missing?

Share this post


Link to post
Share on other sites
Advertisement

When you build a dll, you also produce a link library. The dll contains the code that executes when your program runs. The library contains the linkage information that the linker needs to fill in the blanks frob mentioned. Make sure you add the link library for your dll to the additional libraries in the linker settings for your project.

Share this post


Link to post
Share on other sites

Well, all three assemblies are projects in my solution. I've added them as references and as include folders as nessecary:

Metastorm references EngineBase and DX11Renderer and EngineBase references DX11Renderer

 

Metastorm.h

#ifndef _METASTORM_H_
#define _METASTORM_H_

#include <Windows.h>
#include <WindowsX.h>
#include "Game.h"

class Metastorm : public Game
{
public:
	Metastorm();

	 void Initialize(HINSTANCE hInstance, int nCmdShow, WNDPROC windowProc);

};

#endif

Metastorm.cpp

#include "Metastorm.h"


Metastorm::Metastorm()
{
}

void Metastorm::Initialize(HINSTANCE hInstance, int nCmdShow, WNDPROC windowProc)
{
	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 = L"WindowClass1";

	RegisterClassEx(&wc);

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

	hWnd = CreateWindowEx(NULL,
		L"WindowClass1",
		L"MitOhneHaare.de - DirectX JumpStart",
		WS_OVERLAPPEDWINDOW,
		(GetSystemMetrics(SM_CXSCREEN) - (wr.right - wr.left)) / 2,
		(GetSystemMetrics(SM_CYSCREEN) - (wr.bottom - wr.top)) / 2,
		wr.right - wr.left,
		wr.bottom - wr.top,
		NULL,
		NULL,
		hInstance,
		NULL);

	ShowWindow(hWnd, nCmdShow);
	renderer->Initialize(hInstance, hWnd, 800u, 600u);
}

Game.h

#ifndef _GAME_H_
#define _GAME_H_

#include <Windows.h>
#include <WindowsX.h>
#include "GameTime.h"
#include "Renderer.h"

class __declspec(dllexport) Game
{
public:
	 Game();
	 ~Game();

	Renderer* renderer;

	virtual int Initialize();

	virtual int Update(GameTime* gameTime);
	// Performs rendering operations.
	virtual int Draw(GameTime* gameTime);

	virtual void BeginFrame();
	virtual void EndFrame();

	virtual int Run();

private:
	GameTime* gameTime;
};

#endif

Game.cpp

#include "Game.h"



Game::Game()
{
}


Game::~Game()
{
}

int Game::Initialize()
{
	gameTime = new GameTime();
	renderer = new Renderer();

	return NULL;
}

int Game::Update(GameTime* gameTime)
{
	return NULL;
}

int Game::Draw(GameTime* gameTime)
{
	return NULL;
}

void Game::BeginFrame()
{

}

void Game::EndFrame()
{

}

int Game::Run()
{
	MSG msg;

	Initialize();

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

			if (msg.message == WM_QUIT)
			{
				break;
			}

			BeginFrame();
			Update(gameTime);
			Draw(gameTime);
			EndFrame();
		}
	}

	return msg.wParam;
}

Renderer.h

#ifndef _RENDERER_H_
#define _RENDERER_H_

#pragma comment(lib, "d3d11.lib")

#include <windows.h>
#include <d3d11.h>
#include <dxgi.h>
#include <DirectXMath.h>

class __declspec(dllexport) Renderer
{
public:
	Renderer();
	~Renderer();

	bool Initialize(HINSTANCE hInstance, HWND hwnd, UINT width, UINT height);

	IDXGISwapChain* SwapChain;
	ID3D11Device* d3d11Device;
	ID3D11DeviceContext* d3d11DevCon;
	ID3D11RenderTargetView* renderTargetView;
};

#endif // !_RENDERER_H_

Renderer.cpp

#include "Renderer.h"



Renderer::Renderer()
{
}


Renderer::~Renderer()
{
}

bool Renderer::Initialize(HINSTANCE hInstance, HWND hwnd, UINT width, UINT height)
{
	HRESULT hr;

	//Describe our Buffer
	DXGI_MODE_DESC bufferDesc;

	ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));

	bufferDesc.Width = width;
	bufferDesc.Height = height;
	bufferDesc.RefreshRate.Numerator = 60;
	bufferDesc.RefreshRate.Denominator = 1;
	bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

	//Describe our SwapChain
	DXGI_SWAP_CHAIN_DESC swapChainDesc;

	ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));

	swapChainDesc.BufferDesc = bufferDesc;
	swapChainDesc.SampleDesc.Count = 1;
	swapChainDesc.SampleDesc.Quality = 0;
	swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapChainDesc.BufferCount = 1;
	swapChainDesc.OutputWindow = hwnd;
	swapChainDesc.Windowed = TRUE;
	swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;


	//Create our SwapChain
	hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL,
		D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon);

	//Create our BackBuffer
	ID3D11Texture2D* BackBuffer;
	hr = SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&BackBuffer);

	//Create our Render Target
	hr = d3d11Device->CreateRenderTargetView(BackBuffer, NULL, &renderTargetView);
	BackBuffer->Release();

	//Set our Render Target
	d3d11DevCon->OMSetRenderTargets(1, &renderTargetView, NULL);

	return true;
}

I can call the Initialize function from within Game.cpp (in EngineBase.dll) without problem, but not from Metastorm.cpp (in Metastorm.exe)

 

EDIT: Appearantly at one point I accidentically removed on of the project references, readding it fixed this problem, D'oh ^^

Edited by Lordadmiral Drake

Share this post


Link to post
Share on other sites
Well, all three assemblies

 

 

"Assembly" is a managed code concept; you're writing native code.

 

I can call the Initialize function from within Game.cpp (in EngineBase.dll) without problem, but not from Metastorm.cpp (in Metastorm.exe)

 

 
But do you link the import library (the .lib corresponding to the .dll) in the project settings for the .exe?

Share this post


Link to post
Share on other sites


Well, all three assemblies are projects in my solution. I've added them as references and as include folders as nessecary:
Metastorm references EngineBase and DX11Renderer and EngineBase references DX11Renderer

 

Incorrect terminology aside, that would have been useful information to include in your original post.

 


EDIT: Appearantly at one point I accidentically removed on of the project references, readding it fixed this problem, D'oh ^^

 

Glad you got it sorted out!

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!