Archived

This topic is now archived and is closed to further replies.

darrenhall

Linking problem

Recommended Posts

You''ve probably seen this a million times before, but I''m stumped - I have 3 .cpp files (GameMain.cpp, WinBase.cpp, and InitTerm.cpp) and 1 .h file (Global.h) that I''m writing to create a very simple game. (I''m using MS VC++ on Windows XP, and I''m working with DirectX 8.1 for what its worth.) I''ve defined my function prototypes in my header file and I''m trying to compile my code, but I get errors during the linking process. GameMain.obj : error LNK2001: unresolved external symbol "struct __unnamed G" (?G@@3U__unnamed@@A) WinBase.obj : error LNK2001: unresolved external symbol "struct __unnamed G" (?G@@3U__unnamed@@A) WinBase.obj : error LNK2001: unresolved external symbol "void __cdecl GameShutdown(void)" (?GameShutdown@@YAXXZ) WinBase.obj : error LNK2001: unresolved external symbol "void __cdecl GameMain(void)" (?GameMain@@YAXXZ) WinBase.obj : error LNK2001: unresolved external symbol "bool __cdecl GameInit(void)" (?GameInit@@YA_NXZ) Debug/Tetris.exe : fatal error LNK1120: 4 unresolved externals I recognize that the problem here is a C++ error and it is probably due to the fact that I''m trying to define my methods as extern. My C++ is pretty rusty, and I''m going to buy a primer book, but in the meantime I was hoping for someone here to help me. Here are the definitions from my Globals.h file: //-------------------------------------------------------------- // Function Prototypes //-------------------------------------------------------------- // WinBase.cpp int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int); LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM); // InitTerm.cpp bool GameInit(); void GameShutdown(); // GameMain.cpp void GameMain(); //-------------------------------------------------------------- // Global Variables //-------------------------------------------------------------- #ifndef GLOBALS_OWNERSHIP extern #endif struct { HWND hWnd; HINSTANCE hInstance; BOOL bActive; BOOL bQuitting; // DirectDraw Variables LPDIRECTDRAW7 lpDD; LPDIRECTDRAWSURFACE7 lpDDSPrimary; LPDIRECTDRAWSURFACE7 lpDDSBack; LPDIRECTDRAWSURFACE7 lpDDSRes; LPDIRECTDRAWPALETTE lpDDPalette; // DirectInput Variables LPDIRECTINPUT7 lpDI; LPDIRECTINPUTDEVICE7 lpDIKeyboard; UCHAR KeyState[256]; // DirectSound Variables LPDIRECTSOUND lpDS; LPDIRECTSOUNDBUFFER lpDSB_Sample; } G; So is my problem my C++, or is it a configuration error in the VC++ compiler that I missed? Any help would be appreciated. Thanks

Share this post


Link to post
Share on other sites
I''m not quite sure what you are doing exactly, but if you are using 3 .cpp files for holding extra data for a program, you can declare your functions/classes/variables/etc... in a .h file and have the definitions in a .cpp that includes the corresponding .h file for the declarations and definitions to match up. Then in your main program .cpp, you just include the .h files for the functions/classes/variables/etc... It is essentially the same thing, but a whole lot easier to manage and keep track of. But either way works, just my opinion.

Share this post


Link to post
Share on other sites