Advertisement

[Allegro] Strange and cryptic link error

Started by February 04, 2005 12:55 PM
4 comments, last by 23yrold3yrold 19 years, 7 months ago
I've been writing this game engine and sprite class; the engine really mostly serving as a sprite manager and as a way to make some allegro procedures more transparent. I created a rectangle and point struct with a bunch of functions to work with them and this is where my problems are. Beside that, I have very little idea of what's going wrong. The MSVC error message reads: --------------------Configuration: HenTrans - Win32 Debug-------------------- Compiling... GameEngine.cpp Sprite.cpp HenTrans.cpp Linking... Sprite.obj : error LNK2005: "void __cdecl myCopyRect(struct RECT *,struct RECT *)" (?myCopyRect@@YAXPAURECT@@0@Z) already defined in GameEngine.obj Sprite.obj : error LNK2005: "void __cdecl myInflateRect(struct RECT *,int,int)" (?myInflateRect@@YAXPAURECT@@HH@Z) already defined in GameEngine.obj Sprite.obj : error LNK2005: "bool __cdecl myPtInRect(struct RECT *,struct POINT)" (?myPtInRect@@YA_NPAURECT@@UPOINT@@@Z) already defined in GameEngine.obj Sprite.obj : error LNK2005: "void __cdecl myOffsetRect(struct RECT *,int,int)" (?myOffsetRect@@YAXPAURECT@@HH@Z) already defined in GameEngine.obj Sprite.obj : error LNK2005: "void __cdecl mySetRect(struct RECT *,int,int,int,int)" (?mySetRect@@YAXPAURECT@@HHHH@Z) already defined in GameEngine.obj Sprite.obj : error LNK2005: "int __cdecl myMax(int,int)" (?myMax@@YAHHH@Z) already defined in GameEngine.obj Sprite.obj : error LNK2005: "int __cdecl myMin(int,int)" (?myMin@@YAHHH@Z) already defined in GameEngine.obj Sprite.obj : error LNK2005: "int __cdecl myFoo(int,int)" (?myFoo@@YAHHH@Z) already defined in GameEngine.obj HenTrans.obj : error LNK2005: "void __cdecl myCopyRect(struct RECT *,struct RECT *)" (?myCopyRect@@YAXPAURECT@@0@Z) already defined in GameEngine.obj HenTrans.obj : error LNK2005: "void __cdecl myInflateRect(struct RECT *,int,int)" (?myInflateRect@@YAXPAURECT@@HH@Z) already defined in GameEngine.obj HenTrans.obj : error LNK2005: "bool __cdecl myPtInRect(struct RECT *,struct POINT)" (?myPtInRect@@YA_NPAURECT@@UPOINT@@@Z) already defined in GameEngine.obj HenTrans.obj : error LNK2005: "void __cdecl myOffsetRect(struct RECT *,int,int)" (?myOffsetRect@@YAXPAURECT@@HH@Z) already defined in GameEngine.obj HenTrans.obj : error LNK2005: "void __cdecl mySetRect(struct RECT *,int,int,int,int)" (?mySetRect@@YAXPAURECT@@HHHH@Z) already defined in GameEngine.obj HenTrans.obj : error LNK2005: "int __cdecl myMax(int,int)" (?myMax@@YAHHH@Z) already defined in GameEngine.obj HenTrans.obj : error LNK2005: "int __cdecl myMin(int,int)" (?myMin@@YAHHH@Z) already defined in GameEngine.obj HenTrans.obj : error LNK2005: "int __cdecl myFoo(int,int)" (?myFoo@@YAHHH@Z) already defined in GameEngine.obj LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16 Debug/HenTrans.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. HenTrans.exe - 18 error(s), 0 warning(s) --------------------------------------------------------------------------- Talk about cryptic (well at least to me x_x). Any ideas on what that could mean?
Have you included the .cpp files into the project? I accidently made that mistake last night and was trying to figure you why it wasn't working, then I realized I forgot to add in the .cpp files [lol].

- Drew
Advertisement
I did include them. At first I thought it had something to do with my making my own RECT and POINT structs but I've renamed them all. I also tried implementing a RECT and a couple of functions using RECT in a smaller program and it worked fine. I'm so lost.
Ok, so I fixed the problem by adding the keyword 'inline' before the function calls. I have no idea what inline does. If anyone knows I'd love to know.

But now I've got a brand spanking new rediculously cryptic error message:

--------------------Configuration: HenTrans - Win32 Debug--------------------
Compiling...
Sprite.cpp
Skipping... (no relevant changes detected)
GameEngine.cpp
HenTrans.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/HenTrans.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

HenTrans.exe - 2 error(s), 0 warning(s)
-----------------------------------------------------------------------------

What the hell does that mean!? HELP! PLEASE!!!
Nevermind. I missed an END_OF_MAIN() at the end. Now the bastard just crashes. :( AHHHHH! oh, well. Thanks anyway.
Quote: Original post by hombre08107
Ok, so I fixed the problem by adding the keyword 'inline' before the function calls. I have no idea what inline does. If anyone knows I'd love to know.

Google is your friend. [smile] Anyway, it means the code is re-compiled inline everywhere the function is called as though there were no function and you just wrote the function code where the function call was instead. You obviously defined functions in a header file (usually a big no-no) which then got compiled into every object file you created, and then at linktime, the linker found more than one instance of the function and raised an error. You should be declaring functions in headers and then defining them in one (and only one) source file.

Jesus saves ... the rest of you take 2d4 fire damage.

This topic is closed to new replies.

Advertisement