Jump to content
  • Advertisement
Sign in to follow this  
jdub

Why won't this link

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

I am getting these errors trying to compile this code: 1>GameLibMain.obj : error LNK2001: unresolved external symbol "private: static class GameWindow * GameWindow::gameWnd" (?gameWnd@GameWindow@@0PAV1@A) 1>C:\Projects\GameLibrary\Src\GameLib\Release\GameLib.exe : fatal error LNK1120: 1 unresolved externals Source code:

#include <windows.h>
#include <d3d9.h>
#include <tchar.h>
#include <memory.h>
#include "GameWindow.h"

GameWindow::GameWindow(HINSTANCE instance , int nShowCmd)
{
	this->hInstance = instance;

	//Create and register the window class
	WNDCLASSEX wndClass;
	memset(&wndClass , 0 , sizeof( wndClass ));

	wndClass.cbSize = sizeof( wndClass );
	wndClass.lpfnWndProc = wndProc;
	wndClass.lpszClassName = _T("Game Window");
	wndClass.style = CS_HREDRAW | CS_VREDRAW;
	wndClass.hInstance = instance;
	
	RegisterClassEx(&wndClass);
	
	//Create the window itself
	this->hWnd = CreateWindowEx(0 , 
								_T("Game Window") , 
								_T("Game Window") , 
								WS_OVERLAPPEDWINDOW , 
								0 , 
								0 , 
								200 , 
								200 ,
								NULL ,
								NULL ,
								instance ,
								0);
	if (!this->hWnd)
	{
		return;
	}

	ShowWindow(this->hWnd , nShowCmd);	
}

GameWindow::~GameWindow()
{
	
}

void GameWindow::GameWindowMainLoop()
{
	MSG msg;

	while( GetMessage(&msg , this->hWnd , 0 , 0 ) )
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
}

LRESULT CALLBACK GameWindow::wndProc(HWND inHwnd, UINT inMsg, WPARAM inWParam, LPARAM inLParam)
{
	switch(inMsg)
	{
	case WM_QUIT:
		PostQuitMessage(0);
	}

	return DefWindowProc(inHwnd , inMsg , inWParam , inLParam);
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nShowCmd)
{
	
	GameWindow::CreateGameWindow(hInstance , nShowCmd);
	GameWindow::GetGameWindow()->GameWindowMainLoop();
	GameWindow::KillGameWindow();
}

Header file:

#ifndef GAME_LIB_MAIN_H
#define GAME_LIB_MAIN_H

class GameWindow
{
private:
	static GameWindow* gameWnd;
	HINSTANCE hInstance;
	HWND hWnd;
	
	static LRESULT CALLBACK wndProc(HWND inHwnd, UINT inMsg, WPARAM inWParam, LPARAM inLParam);

public:
	static GameWindow* GetGameWindow() { if (GameWindow::gameWnd == NULL){/* Throw an exeption here */} return gameWnd; }
	
	void GameWindowMainLoop();
	static void CreateGameWindow(HINSTANCE hInstance , int nShowCmd) { gameWnd = new GameWindow(hInstance , nShowCmd); }
	static void KillGameWindow() { delete gameWnd; } 
	GameWindow(HINSTANCE hInstance, int nShowCmd);
	~GameWindow();

};

#endif


What is happening here?

Share this post


Link to post
Share on other sites
Advertisement
For static member variables, you have to implement the actual variable outside the scope of the class declaration. Try adding:

GameWindow* GameWindow::gameWnd = NULL;




to your .cpp file, below the include for GameWindow.h

Hope this helps,
Matt Rudder

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!