Forums
include header file - Printable Version

+- Forums (https://www.vdrift.net/Forum)
+-- Forum: Project (https://www.vdrift.net/Forum/forumdisplay.php?fid=4)
+--- Forum: Development (https://www.vdrift.net/Forum/forumdisplay.php?fid=9)
+--- Thread: include header file (/showthread.php?tid=732)



include header file - mpo - 07-20-2007

I have included an header file (and two global variables) into vamosworld.h to control a virtual reality helmet.
Code:
#ifndef _VAMOSWORLD_H

using namespace std;

#include "font.h"
.....
#include "ai.h"
#include "trackmap.h"

#include "isense.h"  // Virtual Reality Helmet
//Virtual Reality Helmet variable
ISD_TRACKER_HANDLE trackerHandle;
ISD_TRACKER_DATA_TYPE   trackerData;
.....
I need to use these variables and some functions of the helmet into the files vamosworld.cpp and gui.cpp.
When i try to compile, the compiler don't tell me nothing but the linker give to me a lot of errors like:
"multiple definition of trackerHandle" or "multiple definition of trackerData" (the variables that i have defined).
"undefined references to ISD_OpenTracker" (a function of the helmet library).
Why if i have made the definitions into the #ifndef _VAMOSWORLD_H and vamosworld.h is included into vamosworld.cpp and gui.cpp ?
Down here there's a screenshot of a part of the errors:
http://vdrift.net/Gallery/media.php?f=0&sort=0&s=2007072002141515


- joevenzon - 07-20-2007

Why not put your globals in a C file instead of the header? You can access your globals from other C files using the extern keyword.