Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [OpenLayer] undefined reference to vtable?

Credits go to Fladimir da Gorf and ReyBrujo for helping out!
This thread is locked; no one can reply to it. rss feed Print
[OpenLayer] undefined reference to vtable?
Rob Fletcher
Member #2,830
October 2002
avatar

Good Afternoon,

Suddenly, I have been unable to compile my openlayer application. It occurred quite suddenly. It wasn't immediately after I updated from SVN, because I did test out the functionality, however shortly afterwards it started doing this. Obviously, I did something to it, but I can't figure it out. I didn't mess with any OpenLayer files. I just did a make install.

For good measure, I've updated to the latest SVN then make uninstall, make clean, make, make install. (all with the TARGET=WINDOWS & LOCATION=C:\mingw), I tried it again, and got no love. I also cleaned and rebuilt my application. I'm using CodeBlocks IDE.

Curiously, I do use shapes in other code, but they aren't throwing this error. I'd assume it was my own bad code, but it's also in Rectangle.cpp.

It occurs during linking, here are my errors:

undefined reference to `vtable for ol::Shape'
in Rectangle.cpp, Polygon.cpp, and my own CEntity.cpp

The long version goes like this:

C:\MinGW\lib/libopenlayer.a(Polygon.o)(.text+0xa3d): 
Polygon.cpp: undefined reference to `vtable for ol::Shape'

I'm using gcc 3.4.2.

Thanks!
Rob

edit: broke up one of the lines so it wouldn't screw up the formatting.

Fladimir da Gorf
Member #1,565
October 2001
avatar

Hmm... could you try moving the empty virtual functions in Shape.hpp to the source file (Shape.cpp)?

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

Rob Fletcher
Member #2,830
October 2002
avatar

Alright!

That makes some sense, maybe when I rebuilt the software it didn't recognize that the header deep in my mingw/include/OpenLayer had been updated so my build shouldn't have ever worked, but was broken in a working kind of way.

I made the change, I found two empty virtual functions (RotateBy, and ~Shape). There was also 'Shape' the constructor, but it used notation I wasn't familiar with. However, the error changed after I did this, so I figure it wasn't the offending unit.

   Shape( float lineWidth = 1.0 )
      : lineWidth( lineWidth ), displayList( 0 ) {}

Could you explain to me what the stuff after the colon means?

Anyway, my new errors are:

undefined reference to `ol::Shape::MoveTo(ol::Vec2D const&)'
undefined reference to `ol::Shape::TransformBy(ol::Placement const&)'

Those ones are in the Shape.hpp as virtual. Not empty or '= 0'.

Rob

ReyBrujo
Moderator
January 2001
avatar

The original error (vtable): That happens when you declare a virtual function and forget to define it, in example:

class CTest {
    public:
        virtual CTest();
};

Compiling this would throw that error.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Rob Fletcher
Member #2,830
October 2002
avatar

That's weird, because that code snippit I didn't understand was the code for ol::Shape, and it has a little { } after it, so it should be defined, and empty.

Rob

ReyBrujo
Moderator
January 2001
avatar

Yes, the constructor is fine. It seems the problem is that MoveTo and TransformBy are declared as virtual but not defined. As a temporary measure you can define them as empty to see if that works.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

spunit262
Member #5,545
February 2005
avatar

The stuff after the colon is how you pass argument to the constructor of the member variable and, if the class is derived, the constructor of the base class.

Fladimir da Gorf
Member #1,565
October 2001
avatar

The MoveTo and TransformBy in Shape should be defined as empty indeed.

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

Rob Fletcher
Member #2,830
October 2002
avatar

Aha! That did it.

Left Shapes.hpp as it was (empty except for an include) and dropped in a pair of {} after MoveBy and RotateBy, and everything compiled and linked, etc...

I'm not sure why it worked at first and then suddenly didn't. But it's all better now.

Thanks for everybody's help,
Rob

edit:. Ok, it must be something I did. Now primitives aren't being drawn, but they work in the demos. I guess I messed with something without realizing it, I never doubted OpenLayer ;). At least I learned a little something about vtables.

edit: I'm losing my touch! A rebuild and everything is good.

Go to: