Jump to content
  • Advertisement
Sign in to follow this  
Etyrn

Redefinition of 'function name'

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

If you intended to correct an error in the post then please contact us.

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
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.

Share this post


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


-Etyrn

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
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 =)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!