|
From: Vlada D. <dj...@im...> - 2003-06-13 12:25:23
|
----- Original Message -----
From: "Per Westermark" <pw...@ia...>
To: "Vlada Djurovic" <dj...@im...>
Cc: "'DevC++ help'" <dev...@li...>
Sent: Friday, June 13, 2003 1:44 PM
Subject: Re: [Dev-C++] linker errors
> You didn't exactly send any source code for us to look at...
>
> However, if you get multiple declarations of _pGame, I would suspect that
> one header file contains a line 'GameEngine *pGame;' or similar. If that
> include file is used by more than one cpp file (main.cpp and
> GameEngine.cpp) then you'll get a link error.
>
> In the header, the declaration should say 'extern GameEngine *pGame;' and
> then in one of the source files, there should be a 'GameEngine *pGame;'.
>
> Is GameEngine::m_pGameEngine declared as static? In that case, you should
> declare a variable of that type in one of the cpp files.
>
> /Per W
>
Man, this was great!!!!! This is exactly what happens. And you knew it
without even looking at the source? You must be psychic( I hope I spelled it
right :-)).
I didn't send any source, because there are 6 files and I didn't know
exactly what to send. However, the multiple definitions are gone now. As for
the m_pGameEngine, it is declared like this:
class GameEngine
{
protected:
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:
//konstruktor i destruktor
GameEngine(HINSTANCE hInstance,LPTSTR szWindowClass,LPTSTR szTitle,WORD
wIcon,WORD wSmallIcon,
int iWidth=600,int iHeight=480);
virtual ~GameEngine();
//opsti metod
static GameEngine* GetEngine(){return m_pGameEngine;};
BOOL Initialize(int iCmdShow);
LRESULT HandleEvent(HWND hWindow,UINT mag,WPARAM wParam,LPARAM lPAram);
//metodi pristupa
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;};
};
and the constructor is defined like this:
GameEngine::GameEngine(HINSTANCE hInstance,LPTSTR szWindowClass,LPTSTR
szTitle,WORD wIcon,
WORD wSmallIcon,int iWidth,int iHeight)
{
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;
m_bSleep=TRUE;
}
Are you saying that I should declare the variable of that type instead of
'this'?
(If you think I should send entire source, I will, but I'm affraid it's too
long).
>
> On Fri, 13 Jun 2003, Vlada Djurovic wrote:
>
> > Hi.
> >
> > I just got a book about games programming and I got stuck in the first
step.
> > When trying to compile an example from the book, I keep getting linker
> > errors. The output looks like this:
> >
> > C:\Visual\engine\main.o
> > [Warning] In function `GameEngine::GetFrameDelay(void)':
> > //C/Visual/engine/main.cpp(.bss+0x0) C:\Visual\engine\main.cpp(.bss+0x0)
> > multiple definition of `_pGame'
> > //C/Visual/engine/GameEngine.h C:\Visual\engine\skeleton.o(.bss+0x0)
> > first defined here
> > C:\Visual\engine\GameEngine.o
> > [Warning] In function `_10GameEngineP11HINSTANCE__PcT2UsUsii':
> >
> > [Linker error] undefined reference to `GameEngine::m_pGameEngine'
> >
> >
> > I can't figure out what this means. I tried looking for multiple
definitions
> > of _pGame, but I can't find any. Can something else be causing this?
> > As for the other error, m_pGameEngine is a member of GameEngine class
and
> > it's referenced only in the class constructor. Can somebody give me a
hint
> > about possible problems?
> >
> > Thanks.
> > ------------
> > Vlada
> >
> >
> >
> > -------------------------------------------------------
> > This SF.NET email is sponsored by: eBay
> > Great deals on office technology -- on eBay now! Click here:
> > http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
|