obj/Debug/main.o: In function `irrAllocator':
/home/mike/irrlicht/include/irrAllocator.h:26: multiple definition of `device'
obj/Debug/event.o:/home/mike/projects/irrtemp/event.cpp:13: first defined here
obj/Debug/main.o: In function `irrAllocator':
/home/mike/irrlicht/include/matrix4.h:697: multiple definition of `click'
obj/Debug/event.o:/home/mike/projects/irrtemp/event.cpp:5: first defined here
collect2: ld returned 1 exit status
I used to compile fine until I decided to put my event handler in a separate .cpp file, then I started getting this error. I put everything back like it was before I moved it to the separate file and I'm still getting the error.
what is IrrlichtDevice* device = 0; doing in event receiver? i think this might be an error. Keep device, scene manager and driver 'in one place'. If you need to use them remotely then make their structure (i made VideoEngine object myself) and pass it to that constructors which class needs them.
extern IrrlichtDevice* device = 0;
extern core::position2d<s32> click = core::position2d<s32>(0,0);
//Tells the linker and compiler that the variables are not actual parts of this .cpp but another .cpp
If you don't have anything nice to say, don't say anything at all.
I've tried making them extern but it's of no use. The reason device is set to 0 is because it won't compile if I don't. I get an error saying "device not declared in this scope" because the variable is declared in main.cpp but is used in event.cpp. I'll post the contents of main.cpp when I get home.
I only did the extern in event.cpp and I already found that page, but thanks anyways. I'm seriously thinking it has something to do with the file being named event. I'll try naming it something else when I get home. Like i said before, it compiles fine if I put all the code in main.cpp.
Sorry it took so long for me to post this, I just don't have much time between school and work. I finally had some time to play with it. The code is now organized in two files, main.cpp and myReceiver.cpp. I'm still getting the same error. Here's something strange though, I got it to work.
I'm using codeblocks svn3816 which is fairly new. I noticed that if I removed myReceiver.cpp from my project it compiled just fine. I think it's probably a bug in codeblocks. Pretty strange.
It's very rarely the tool which has the bug. In your case the error message is quite clear: Those variables have been defined more than once. My guess would be that you include that .cpp file somewhere, as that would cause that problem. And it looks like you do not yet understand the difference between declarations and definitions in c++ (looks more like java) so you might read up some more on that topic.
There are only two .cpp files and only one of those files has declares for my variables. They are definitely only declared once. The file is still #included in my main.cpp but I only get errors when I add it as part of my codeblocks project. If it was an error with the code, wouldn't I still get the error?
When both your main.cpp and event.cpp are part of your project and you include event.cpp additionally in main.cpp then it will be defined twice. Each cpp file in your project results in it's own object file. And any file included can just be seen as part of that file (it's as if you did copy&paste the whole content at the position of the #include). So you will get now an event.o where those variables are defined and additionally you will have an main.o which does include the whole event.cpp and therefore does also hold all that definitions. And when the object files are linked that definitions are now there twice with the same name and you get therefore those linker errors.
Simply don't include a .cpp file, you never have to do so. Put declarations in a header and include that. If you're not sure what's up with that declaration/definition stuff do read up on that. You will simply need to know about that when working with c++.