Skip to main content
gamedev.net
🔒 Locked

MORE LINKING PROBLEMS

Started by Nullio 2 replies 700+ views
Original Post
Nullio
Nullio
here's the error Main.hpp is where the WinMain and Messageing loop is CGameEngine.hpp/cpp is a class that does game stuff Globals.hpp Holds global variables This is the top of Main.hpp
          
#define WIN32_LEAN_AND_MEAN		
#define ENGINEMAIN_INCLUDED		

#ifndef INITGUID
	#define INITGUID
#endif


#ifndef WINSTUFF
	#include <windows.h>   
	#include <windowsx.h>
	#include <stdio.h> 
	#include <math.h> 
	#define WINSTUFF
#endif

#include "ddraw.h"

#ifndef GLOBALS_INCLUDED
	#include "Globals.hpp"
#endif


#include "CGameEngine.hpp"
  
This is the top of Globals.hpp
                    
#ifndef WINSTUFF
	#include <windows.h>   
	#include <windowsx.h>
	#include <stdio.h> 
	#include <math.h> 
	#define WINSTUFF
#endif


#define GLOBALS_INCLUDED
  
And this is the top of CTileEngine.cpp
  
#define CGAMEENGINE_INCLUDED

#ifndef GLOBALS_INCLUDED
	#include "Globals.hpp"
#endif

#ifndef __DDRAW_INCLUDED__
	#include "ddraw.h"
#endif

#include "CGameEngine.hpp"



int CGameEngine::StartDirectDraw(int iWidth, int iHeight, int iBpp) {


	.
        .
        .
}
  
So why am I getting linking errors about variables that are declared in global.hpp being declared twice??? and also is this a good way of setting things up?? Thanks in advance Edited by - Nullio on December 19, 2001 7:38:41 PM Edited by - Nullio on December 19, 2001 7:40:28 PM Edited by - Nullio on December 19, 2001 7:42:17 PM Edited by - Nullio on December 19, 2001 7:44:36 PM
jenova
jenova
because when you link it, it is defined twice.

once in "CGameEngine.obj" and once in "CMain.obj".

what you want to do is use the keyword "extern". although i try to stay far, far away from that keyword.

better yet, if you''re using classes just define a "static public" member.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Nullio
Nullio
could you elaborate on using a "static public" member
jenova
jenova
well, you have your class "CGameEngine".

// header file containing the "CGameEngine" declaration.
  
class CGameEngine {
public:
static int m_iSomeMember;
};


// some other "cpp" file.
// make sure you include the header file with the "CGameEngine" declaration.
  
void SomeFunction(void)
{
// this member can be accessed by anything.

CGameEngine::m_iSomeMember = 0;
}


To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Topic Locked

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

Sign in to reply to this topic.