a little of c++

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
kaos
Posts: 155
Joined: Tue Aug 12, 2008 8:25 pm
Location: Spain

a little of c++

Post by kaos »

If I include #include "ARToolKitPlus/TrackerSingleMarkerImpl.h" in a simple file, main.cpp, work perfect.

but if I include #include "ARToolKitPlus/TrackerSingleMarkerImpl.h" in other header, for example CGame.h, not work.

¿what's the problem?

.objs\main.o:main.cpp:(.text+0x3b2e): multiple definition of `ARToolKitPlus::CameraImpl::CameraImpl()'
.objs\VideoAR.o:VideoAR.cpp:(.text+0x3a30): first defined here
.objs\main.o:main.cpp:(.text+0x3b4a): multiple definition of `ARToolKitPlus::CameraImpl::CameraImpl()'
.objs\VideoAR.o:VideoAR.cpp:(.text+0x3a4c): first defined here
.....
jeetee
Posts: 15
Joined: Tue Oct 13, 2009 3:09 pm
Contact:

Post by jeetee »

It seems that TrackerSingleMarkerImpl.h does not contain pre-compiler-directives to prevent the file from being included more than once in a given source-file.
Most probably you've included this header in VideoAR and have included both VideoAR as well as TSMI.h in your main. The result is that TSMI.h is included twice in main in the end, and thus those defenitions are duplicated.

Here's the code-concept to fix this kind of error.

code of someheader.h

Code: Select all

#ifndef SOMEHEADER_H
#define SOMEHEADER_H
//here comes all the code of the header as always
#endif SOMEHEADER_H
This will prevent the definitions of the headerfile to be included more than once in your project, and thus prevent the compilererror you're getting.

[EDIT]
On a sidenote: this is far from an advanced question imo, but rather the basics of correct understanding of classes and compilation. I'd advise you to go and learn more about Classes, if not, you'll probably have a rather hard time starting to work with irrlicht.
Just my 2c
[/EDIT]
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Moreover, this question is not Irrlicht related at all. I move it to Beginner's
Anyway, the compile guards will probably not help. It looks like some global variable was defined in a header. You can declare variables in headers, definitions have to happen in a .cpp file or have to be static.
Post Reply