Sign in to follow this  
Etyrn

Redefinition of 'function name'

Recommended Posts

This is confusing the heck outta me. I can't figure out how to fix these linker errors, as I've already done the "no def" trick. gui.cpp
#include "gui.h"
#include "game.h"

extern cGUI* client;
#ifdef _DEBUG_CLIENT_
   #include "error.h"
   extern DebugIO* error;
#endif
//code
game.cpp
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include "game.h"
#include "gui.h"
#include "image.h"
//code
game.h
#ifndef _GAME_H_
#define _GAME_H_

#include "gui.h"

#ifdef _DEBUG_CLIENT_
   #include "error.h"
   DebugIO* error = new DebugIO("error.txt");

   bool glInit();
   bool renderBG();
#else
   void glInit();
   void renderBG();
#endif

void renderScreen();
void FPS(int);
void mouseDown(int,int,int,int);
void mouseMove(int,int);
void keyboardNormal(unsigned char,int,int);
void keyboardSpecial(int,int,int);
void glCleanUp();
void windowResize(int,int);

int fps = 0;
GLint bgTexture;

cGUI* client = new cGUI;

#endif
The linker claims of redefinitions of every function in game.h... and I'm confuzzled. Gui.cpp needs game.h for glCleanUp. :/ Any and all help is appreciated. -Etyrn

Share this post


Link to post
Share on other sites
You're not doing the #ifndef trick, but I don't think its going to help you.

#ifndef YOUR_DEF_HERE
#define YOUR_DEF_HERE

...code...

#endif




You don't even have any ifndefs.

And do not put variable definitions in a .h file. At least not non-class variables.

**whatever.cpp**
DebugIO* error = new DebugIO("error.txt");


**whatever.h**
extern DebugIO* error;


This will make any file that includes whatever.h be able to use error.

Edit: You already use externs, but you still declare some variables in the .h file.

Share this post


Link to post
Share on other sites

// game.h

int fps = 0;
GLint bgTexture;

cGUI* client = new cGUI;



You cannot have definitions in header files. Some time or other you will get nasty errors. You need to use the "extern" keyword in header files, and provide the definitions in exactly one source file:


// game.cpp

int fps = 0;
GLint bgTexture;
cGUI* client = new cGUI;




//game.h

extern int fps;
extern GLint bgTexture;
extern cGUI* client;


Share this post


Link to post
Share on other sites
You have one #ifndef, but what about gui.h?

Also, may I point out this article?

Edit: wrong article, lemmee find the right one. Though that one might still be good to read.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ezbez
You have one #ifndef, but what about gui.h?

Also, may I point out this article?

Edit: wrong article, lemmee find the right one. Though that one might still be good to read.


I used to organise my headers with a single Global.h that included all my other includes. I found though that when working with a larget project this really caused problems, as any mistake in a header file would cause every single .cpp file to be recompiled whether it was needed or not =/

For smaller projects using a single Global.h that all .cpp files include is definitely helpful. During development of a larger project it can be a nightmare =/

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this