Skip to main content
GameDev.net gamedev.net
🔒 Locked

I need help I'm getting compiler errors

Started by Regretfulone Jul 3, 2009 at 11:34 PM 15 replies 2k views
Original Post
Regretfulone
Regretfulone
OK so when I try and compile my UFO game I keep getting these errors: error LNK2019: unresolved external symbol "void __cdecl MouseMove(int,int)" error LNK2019: unresolved external symbol "void __cdecl MouseButtonUp(int,int,bool)" error LNK2019: unresolved external symbol "public:void __thiscall Bitmap::Draw(struct HDC__ *,int,int,int,bool,unsigned long)" error LNK2019: unresolved external symbol "public: __thiscall Bitmap::Bitmap(struct HDC__ *, unsigned int, struct, HINSTANCE__ *) the MouseMove and MouseButtonDown functions are part of my game engine, and the Bitmap references a Bitmap class I have created. Please help! >< (I can post code if needed)
jpetrie
jpetrie
These are link errors, not compile errors. They are telling you that you declared a function called MouseMove that takes two integers which will not return a value... but that when it came time to assemble the final program from all the compiled translation units, no such function was found.

This could mean a variety of things. The most obviously is that you did not define the function at all, but only declared it (for example, in a header file). More subtle is that perhaps you are not linking the correct library, or that the source file containing the definition is not being compiled, or that there is a function defined that is similar to MouseMove but differs slightly in name or signature.

The same is true for the rest of the errors. Post the code where you declare MouseMove and the code where you define it. I would expect the former to be in a header file and the latter a source file.
Regretfulone
Regretfulone
ok well I might not have time today to post it. I think I will a little later but all of the code you asked me to post is in my Game Engine Header. It is declared at the top of the file and then the code is later. I will post later today the actual code though. Thank you for your help :) I really appreciate it.
Regretfulone
Regretfulone
ok i won't post the whole game engine header here but I'll post the sections that are relevant...


bool GameInitialize(HINSTANCE hInstance);
void GameStart(HWND hWindow);
void GameEnd();
void GameActivate(HWND hWindow);
void GameDeactivate(HWND hWindow);
void GamePaint(HDC hDC);
void GameCycle();
void HandleKeys();
void MouseButtonDown(int x, int y, bool bLeft);
void MouseButtonUp(int x, int y, bool bLeft);
void MouseMove(int x, int y);


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;

case WM_LBUTTONDOWN:
//Handle left mouse button press
MouseButtonDown(LOWORD(lParam), HIWORD(lParam), true);
return 0;

case WM_LBUTTONUP:
//Handle left mouse button release
MouseButtonUp(LOWORD(lParam), HIWORD(lParam), true);
return 0;

case WM_RBUTTONDOWN:
//Handle right mouse button press
MouseButtonDown(LOWORD(lParam), HIWORD(lParam), false);
return 0;

case WM_RBUTTONUP:
//Handle right mouse button release
MouseButtonUp(LOWORD(lParam), HIWORD(lParam), false);
return 0;

case WM_MOUSEMOVE:
//Handle mouse movement
MouseMove(LOWORD(lParam), HIWORD(lParam));
return 0;
}
return DefWindowProc(hWindow, msg, wParam, lParam);
}


SiCrane
SiCrane
The first linker error says that the linker can't find a definition for MouseMove(). Do you have a MouseMove() function definition?
Ying
Ying
Your compiler finds the function declarations (the prototypes) but not the "content" (the actual function definitions).

That means you either:
- Haven't included the .c/cpp files. (If using code)
- Haven't included the .lib or .dll where the functions are (if you're using libraries)
- Have included one of the above, but the path to find them is wrong.

If you're using visual studio, right click on the function name, select "definition" and see if an error pops up. If it does, it's the above issue.
Regretfulone
Regretfulone
When I right click it and click the go to definition option it goes right to the declaration. (Yes I am using visual studio c++ 2008 Express) When I go down into the code where the MouseMove() function is and right click and go to the declaration it goes to the void MouseMove(int, int) declaration and it also goes there for the definition. I don't know if it should be going there but the definition for void MouseMove(int,int) is itself.
Regretfulone
Regretfulone
I think I may have figured out my problem. -.- I didn't reference the actual functions in the program even though there isnt specific code for them..i feel stupid haha. That worked for the first two linker errors. I'm raelly not sure about the other two though.

Here they are again:

Game.obj : error LNK2019: unresolved external symbol "public: __thiscall Bitmap::Bitmap(struct HDC__ *,unsigned int,struct HINSTANCE__ *)" (??0Bitmap@@QAE@PAUHDC__@@IPAUHINSTANCE__@@@Z) referenced in function "void __cdecl GameStart(struct HWND__ *)" (?GameStart@@YAXPAUHWND__@@@Z)
Game.obj : error LNK2019: unresolved external symbol "public: void __thiscall Bitmap::Draw(struct HDC__ *,int,int,bool,unsigned long)" (?Draw@Bitmap@@QAEXPAUHDC__@@HH_NK@Z) referenced in function "void __cdecl GamePaint(struct HDC__ *)" (?GamePaint@@YAXPAUHDC__@@@Z)

daviangel
daviangel
Quote:
Original post by Regretfulone
I think I may have figured out my problem. -.- I didn't reference the actual functions in the program even though there isnt specific code for them..i feel stupid haha. That worked for the first two linker errors. I'm raelly not sure about the other two though.

Here they are again:

Game.obj : error LNK2019: unresolved external symbol "public: __thiscall Bitmap::Bitmap(struct HDC__ *,unsigned int,struct HINSTANCE__ *)" (??0Bitmap@@QAE@PAUHDC__@@IPAUHINSTANCE__@@@Z) referenced in function "void __cdecl GameStart(struct HWND__ *)" (?GameStart@@YAXPAUHWND__@@@Z)
Game.obj : error LNK2019: unresolved external symbol "public: void __thiscall Bitmap::Draw(struct HDC__ *,int,int,bool,unsigned long)" (?Draw@Bitmap@@QAEXPAUHDC__@@HH_NK@Z) referenced in function "void __cdecl GamePaint(struct HDC__ *)" (?GamePaint@@YAXPAUHDC__@@@Z)

Sounds like you forgot to link the gameengine to your program.This looks and sounds like a program from the Mike Morrison Win32 game programming book and if I remember that was one of the annoying things about the book is that he decided to write his own buggy Bitmap class that you need to include.
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
Regretfulone
Regretfulone
Actually yes, I am working from the book Teach Yourself Game Programming in 24 Hours. And yeah, he talks about creating your own Bitmap class and those two errors that are listed occur because of the bitmap class. Is the Bitmap class really necessary?

To the comment of not including GameEngine.h, no it was included I just didn't have MouseMove() and MouseButtonUp() listed in the actual Game.cpp file. I figured that much out. But I'm stumped on the other errors.
daviangel
daviangel
Quote:
Original post by Regretfulone
Actually yes, I am working from the book Teach Yourself Game Programming in 24 Hours. And yeah, he talks about creating your own Bitmap class and those two errors that are listed occur because of the bitmap class. Is the Bitmap class really necessary?

To the comment of not including GameEngine.h, no it was included I just didn't have MouseMove() and MouseButtonUp() listed in the actual Game.cpp file. I figured that much out. But I'm stumped on the other errors.

Unfortunately Win32 doesn't make it easy to load bitmpaps like DirectX or Allegro,etc so you'd have to use something like LoadImage() and rewrite all your code so yeah if you want to follow the book you're stuck with using his Bitmap class.
It's fixable though if you C++ skills are decent. I know I did and I might still have the code I used laying around somewhere.
And the author used to have updated code for this book at his website and even a very helpful forum but I don't know if he got fed up with it or what but it's gone now so goodluck with that.
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
Regretfulone
Regretfulone
well I'm still new with the c++ skills. I have a basic understanding of it but I'm learning more as I go through the books. I hope you can help me if maybe you could find how you changed the bitmap class or if you'd like I can post the whoel class here it's pretty short so.
Developer_X
Developer_X
I bought that book ages ago. It was only good for inspiring me.
I didn't learn a thing from it. I was already way past that level at the time. Go figure.

If my memory serves. The full code for the class is not in the book, but it is on the companion CD-ROM.

If you copy the files for the class into your project it should compile.

I can dig through my stuff and look for it if you cannot find it.
Regretfulone
Regretfulone
Could you please do that because I don't have the CD. I rented this book from the public library and the disc was not with it idk what happened to the disk.
daviangel
daviangel
Quote:
Original post by Regretfulone
Could you please do that because I don't have the CD. I rented this book from the public library and the disc was not with it idk what happened to the disk.

Looks like the author has reposted the sourcecode you need from the book on his website.
Get it while you can it's a 84MB download.
I just tested it with VS2008 and it seems to compile/work okay so you shouldn't have any further problems.
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
Regretfulone
Regretfulone
Thanks, that isn't the right book but it's ok I found the code elsewhere. it still isn't working for me but it's ok I have another book and I am gonna try and look through it for a bitmap solution XD

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.