Redefinition of 'function name'

Started by
8 comments, last by Etyrn 17 years, 10 months ago
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
Advertisement
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.
I don't? O_o

Then what's with that #ifndef _GAME_H_ at the top of ehm... game.h?


-Etyrn

Edit: Fixed the class inits. :P
// game.hint 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.cppint fps = 0;GLint bgTexture;cGUI* client = new cGUI;


//game.hextern int fps;extern GLint bgTexture;extern cGUI* client;

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.
Alright! Working great now, and I learned a valuable lesson. :O
Thankens!


-Etyrn
Oh, and here's the article I was looking for.
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 =/

"Leave it to the computer programmers to shorten the "Year 2000 Millennium Bug" to "Y2K." Isn't that what caused this problem in the first place?"
Quote:Original post by Ezbez
Oh, and here's the article I was looking for.


lol, yeah thats definitely a better article. Hopefully my post before still makes some sense =)
"Leave it to the computer programmers to shorten the "Year 2000 Millennium Bug" to "Y2K." Isn't that what caused this problem in the first place?"
Oops, just noticed your post. Yes I do have the ifndefs in gui.h, but I didn't post that. I posted gui.cpp. :P


-Etyrn

Edit: And thanks for the article.

This topic is closed to new replies.

Advertisement