Public Group

Redefinition of 'function name'

This topic is 4395 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 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 on other sites
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

Share on other sites
// 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;

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

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

Share on other sites
Alright! Working great now, and I learned a valuable lesson. :O
Thankens!

-Etyrn

Share on other sites
Oh, and here's the article I was looking for.

Share on other sites
Quote:
 Original post by EzbezYou 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 on other sites
Quote:
 Original post by EzbezOh, and here's the article I was looking for.

lol, yeah thats definitely a better article. Hopefully my post before still makes some sense =)

Share on other sites
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.

• 10
• 9
• 48
• 12
• 10
• Forum Statistics

• Total Topics
631384
• Total Posts
2999701
×

Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!