[OpenLayer] undefined reference to vtable?
Rob Fletcher

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

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

Rob Fletcher

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

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.

Rob Fletcher

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

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.

spunit262

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

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

Rob Fletcher

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.

Thread #575663. Printed from Allegro.cc