[Solved] OnEvent compiles, but linker dies mysteriously

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
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

[Solved] OnEvent compiles, but linker dies mysteriously

Post by kormoran »

The facts: I tried my own (first) code after studying examples, app compiles but linker dies without any message error :shock:
And Code::Blocks shows the first line of the OnEvent method implementation, as if the error was here somewhere... is it so?

Error reported by IDE:
||=== Build: Debug in CamelCAM (compiler: GNU GCC Compiler) ===|
obj\Debug\EventHandlers.o:D:\src\CamelCAM\EventHandlers.cpp|25|first defined here|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
Infos:
I'm on win7 x64 sp1, using TDM mingw x64 5.2.0 and Code::Blocks 15.12;
I compiled Irrlicht with this IDE/compiler and all went fine, every examples compiled and worked perfectly.

Code of the receiver class is taken mostly from an example code, I just added more event handling and put it in a class and .cpp file on its own:

Code: Select all

class CamelBaseReceiver : public irr::IEventReceiver{
public:
 
    struct SMouseState MouseState;
    CamelBaseReceiver();
    virtual bool OnEvent(const SEvent &event);
    virtual bool IsKeyDown(EKEY_CODE keyCode) const;
 
private:
    bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
 
implementation of OnEvent method:

Code: Select all

bool CamelBaseReceiver::OnEvent(const SEvent &event){
    switch(event.EventType)
    {
        case EET_GUI_EVENT:
        {
            s32 id = event.GUIEvent.Caller->getID();
            switch(event.GUIEvent.EventType)
            {
            // etc. etc...
 
Can anyone point me to a solution? Thank you...
Last edited by kormoran on Sun Jan 17, 2016 8:46 pm, edited 1 time in total.
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

Re: OnEvent compiles, but linker dies mysteriously

Post by kormoran »

Could be a kind of "compiler too new" error, found someone reporting similar problems.
Adding "override" to OnEvent in ISceneNodeAnimator does no good.
Next try: fiddling with compiler options...
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: OnEvent compiles, but linker dies mysteriously

Post by CuteAlien »

Something is defined twice. Although usually it gives a little more information in the error - did you really copy-paste everything?
Can't tell more with the given information - check what's in line 25 in D:\src\CamelCAM\EventHandlers.cpp.
Could also be a missing header guard.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

Re: OnEvent compiles, but linker dies mysteriously

Post by kormoran »

CuteAlien wrote:Something is defined twice. Although usually it gives a little more information in the error - did you really copy-paste everything?
I copypasted the code involved, not the whole file(s). Header guards are in place in every .h file I created and all #endif are present (checked right now).
Er... if you mean the compiler output instead, yes that's all I got :(

Line 25 is the definition (not declaration) of the OnEvent method:

Code: Select all

bool CamelBaseReceiver::OnEvent(const SEvent &event){
// etc. etc...
 
I discovered that Gcc 5.2.0 honors overrides only with -std=c++11 option. I tried to recompile Irrlicht with -std=c++11, but fails to build (D:\irrlicht-1.8.3\source\Irrlicht\aesGladman\sha2.cpp|392|error: narrowing conversion of '13096744586834688815ull' from 'long long unsigned int' to 'sha2_64t {aka long long int}' inside { } [-Wnarrowing]).

I recompiled my own code with -std=c++11, but the error stays.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: OnEvent compiles, but linker dies mysteriously

Post by CuteAlien »

I don't think this is about Irrlicht. As the error says the involved files are EventHandlers.o (probably generated from some EventHandlers.cpp file) and src\CamelCAM\EventHandlers.cpp
Both of those files are not part of Irrlicht.

Irrlicht also doesn't need std=c++11 yet (I've already spend some time looking in the aes stuff, I think I can work around it for now, but still looking if I should update some stuff while doing so. Will hopefully be fixed in 1-2 weeks).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

Re: OnEvent compiles, but linker dies mysteriously

Post by kormoran »

SOLVED.

Instead of defining the event handler class in a separated .cpp file, I put it in the "main.cpp" file, where main() is defined, like in the Irrlicht examples. Now all my code is working fine, though probably it's not the most elegant solution... oh well :roll:
Post Reply