Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VC++ 5.0 error LNK2001: Unresolved External Symbol

Status
Not open for further replies.

slphosts

Programmer
May 18, 2006
2
0
0
GB
Hi I have been following "Sams Teach Yourself Game Programming In 24 Hrs" and have hit an error on creating the GameEngine I get a LNK2001 error below is my log:

--------------------Configuration: GameEngine - Win32 Debug--------------------
Begining build with project "D:\Program Files\DevStudio\MyProjects\GameEngine\GameEngine.dsp", at root.
Active configuration is Win32 (x86) Application (based on Win32 (x86) Application)

Project's tools are:
"32-bit C/C++ Compiler for 80x86" with flags "/nologo /MLd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Fp"Debug/GameEngine.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /c "
"OLE Type Library Maker" with flags "/nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 "
"Win32 Resource Compiler" with flags "/l 0x809 /fo"Debug/Skeleton.res" /d "_DEBUG" "
"Browser Database Maker" with flags "/nologo /o"Debug/GameEngine.bsc" "
"COFF Linker for 80x86" with flags "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:no /pdb:"Debug/GameEngine.pdb" /debug /machine:I386 /out:"Debug/GameEngine.exe" /pdbtype:sept "
"Custom Build" with flags ""
"<Component 0xa>" with flags ""

Creating temp file "C:\DOCUME~1\Sam\LOCALS~1\Temp\RSP105.tmp" with contents </nologo /MLd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Fp"Debug/GameEngine.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /c
"D:\Program Files\DevStudio\MyProjects\GameEngine\Skeleton.cpp"
>
Creating command line "cl.exe @C:\DOCUME~1\Sam\LOCALS~1\Temp\RSP105.tmp"
Creating temp file "C:\DOCUME~1\Sam\LOCALS~1\Temp\RSP106.tmp" with contents <kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:no /pdb:"Debug/GameEngine.pdb" /debug /machine:I386 /out:"Debug/GameEngine.exe" /pdbtype:sept
".\Debug\Skeleton.res"
".\Debug\Skeleton.obj">
Creating command line "link.exe @C:\DOCUME~1\Sam\LOCALS~1\Temp\RSP106.tmp"
Compiling...
Skeleton.cpp
Linking...
Skeleton.obj : error LNK2001: unresolved external symbol "protected: static class GameEngine * GameEngine::m_pGameEngine" (?m_pGameEngine@GameEngine@@1PAV1@A)
Skeleton.obj : error LNK2001: unresolved external symbol "void __cdecl GameStart(void *)" (?GameStart@@YAXPAX@Z)
Debug/GameEngine.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.



GameEngine.exe - 3 error(s), 0 warning(s)
----------------------------------------------------------

and here is my GameEngine.h:

bool GameInitialize(HINSTANCE hInstance);
void GameStart(HWND hWindow);
void GameEnd();
void GameActivate(HWND hWindow);
void GameDeactivate(HWND hWindow);
void GamePaint(HDC hDC);
void GameCycle();

class GameEngine
{
protected:
// Member Variables
static GameEngine* m_pGameEngine;
HINSTANCE m_hInstance;
HWND m_hWindow;
TCHAR m_szWindowClass[32];
TCHAR m_szTitle[32];
WORD m_wIcon, m_wSmallIcon;
int m_iWidth, m_iHeight;
int m_iFrameDelay;
bool m_bSleep;

public:
// Constructor(s)/Destructor
GameEngine(HINSTANCE hInstance, LPTSTR szWindowClass,
LPTSTR szTitle, WORD wIcon, WORD wSmallIcon, int iWidth = 640,
int iHeight = 480);
virtual ~GameEngine();

// General Methods
static GameEngine* GetEngine() { return m_pGameEngine; };
bool Initialize(int iCmdShow);
LRESULT HandleEvent(HWND hWindow, UINT msg, WPARAM wParam,
LPARAM lParam);

// Accessor Methods
HINSTANCE GetInstance() { return m_hInstance; };
HWND GetWindow() { return m_hWindow; };
void SetWindow(HWND hWindow) { m_hWindow = hWindow; };
LPTSTR GetTitle() { return m_szTitle; };
WORD GetIcon() { return m_wIcon; };
WORD GetSmallIcon() { return m_wSmallIcon; };
int GetWidth() { return m_iWidth; };
int GetHeight() { return m_iHeight; };
int GetFrameDelay() { return m_iFrameDelay; };
void SetFrameRate(int iFrameRate) { m_iFrameDelay = 1000 /
iFrameRate; };
bool GetSleep() { return m_bSleep; };
void SetSleep(bool bSleep) { m_bSleep = bSleep; };
};

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
MSG msg;
static int iTickTrigger = 0;
int iTickCount;

if (GameInitialize(hInstance))
{
// Initialize the game engine
if (!GameEngine::GetEngine()->Initialize(iCmdShow))
return FALSE;

// Enter the main message loop
while (TRUE)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// Process the message
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// Make sure the game engine isn't sleeping
if (!GameEngine::GetEngine()->GetSleep())
{
// Check the tick count to see if a game cycle has elapsed
iTickCount = GetTickCount();
if (iTickCount > iTickTrigger)
{
iTickTrigger = iTickCount +
GameEngine::GetEngine()->GetFrameDelay();
GameCycle();
}
}
}
}
return (int)msg.wParam;
}

// End the game
GameEnd();

return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Route all Windows messages to the game engine
return GameEngine::GetEngine()->HandleEvent(hWindow, msg, wParam, lParam);
}


GameEngine::GameEngine(HINSTANCE hInstance, LPTSTR szWindowClass,
LPTSTR szTitle, WORD wIcon, WORD wSmallIcon, int iWidth, int iHeight)
{
// Set the member variables for the game engine
m_pGameEngine = this;
m_hInstance = hInstance;
m_hWindow = NULL;
if (lstrlen(szWindowClass) > 0)
lstrcpy(m_szWindowClass, szWindowClass);
if (lstrlen(szTitle) > 0)
lstrcpy(m_szTitle, szTitle);
m_wIcon = wIcon;
m_wSmallIcon = wSmallIcon;
m_iWidth = iWidth;
m_iHeight = iHeight;
m_iFrameDelay = 50; // 20 FPS default
m_bSleep = TRUE;
}

GameEngine::~GameEngine()
{
}

bool GameEngine::Initialize(int iCmdShow)
{
WNDCLASSEX wndclass;

// Create the window class for the main window
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = m_hInstance;
wndclass.hIcon = LoadIcon(m_hInstance,
MAKEINTRESOURCE(GetIcon()));
wndclass.hIconSm = LoadIcon(m_hInstance,
MAKEINTRESOURCE(GetSmallIcon()));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = m_szWindowClass;

// Register the window class
if (!RegisterClassEx(&wndclass))
return FALSE;

// Calculate the window size and position based upon the game size
int iWindowWidth = m_iWidth + GetSystemMetrics(SM_CXFIXEDFRAME) * 2,
iWindowHeight = m_iHeight + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 +
GetSystemMetrics(SM_CYCAPTION);
if (wndclass.lpszMenuName != NULL)
iWindowHeight += GetSystemMetrics(SM_CYMENU);
int iXWindowPos = (GetSystemMetrics(SM_CXSCREEN) - iWindowWidth) / 2,
iYWindowPos = (GetSystemMetrics(SM_CYSCREEN) - iWindowHeight) / 2;

// Create the window
m_hWindow = CreateWindow(m_szWindowClass, m_szTitle, WS_POPUPWINDOW |
WS_CAPTION | WS_MINIMIZEBOX, iXWindowPos, iYWindowPos, iWindowWidth,
iWindowHeight, NULL, NULL, m_hInstance, NULL);
if (!m_hWindow)
return FALSE;

// Show and update the window
ShowWindow(m_hWindow, iCmdShow);
UpdateWindow(m_hWindow);

return TRUE;
}

LRESULT GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam,
LPARAM lParam)
{
// Route Windows messages to game engine member functions
switch (msg)
{
case WM_CREATE:
// Set the game window and start the game
SetWindow(hWindow);
GameStart(hWindow);
return 0;

case WM_ACTIVATE:
// Activate/deactivate the game and update the Sleep status
if (wParam != WA_INACTIVE)
{
GameActivate(hWindow);
SetSleep(FALSE);
}
else
{
GameDeactivate(hWindow);
SetSleep(TRUE);
}
return 0;

case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hWindow, &ps);

// Paint the game
GamePaint(hDC);

EndPaint(hWindow, &ps);
return 0;

case WM_DESTROY:
// End the game and exit the application
GameEnd();
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWindow, msg, wParam, lParam);
}

 
No static GameEngine* m_pGameEngine member var definition, you have its declaration only (link error #1). Where is
Code:
GameEngine::m_pGameEngine = 0;
?
Where is external function void GameStart(HWND hWindow) body or lib with this function (link error #2)?
 
the rest of the functions are in another file skeleton.cpp
 
NO void GameStart(void*) body in sceleton.obj (i.e. in sceleton.cpp: unresolved external symbol there).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top