Undefined symbols "vtable for ..." and "typeinfo for..."?

Lisa picture Lisa · Nov 7, 2009 · Viewed 41.4k times · Source

Nearly the final step but still some strange erros....

bash-3.2$ make
g++ -Wall -c -g Myworld.cc
g++ -Wall -g solvePlanningProblem.o Position.o AStarNode.o PRM.o PRMNode.o World.o SingleCircleWorld.o Myworld.o RECTANGLE.o CIRCLE.o -o solvePlanningProblem
Undefined symbols:
  "vtable for Obstacle", referenced from:
      Obstacle::Obstacle()in Myworld.o
  "typeinfo for Obstacle", referenced from:
      typeinfo for RECTANGLEin RECTANGLE.o
      typeinfo for CIRCLEin CIRCLE.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [solvePlanningProblem] Error 1

What's the meaning of vtable and typeinfo?

Answer

Mike Seymour picture Mike Seymour · Nov 7, 2009

If Obstacle is an abstract base class, then make sure you declare all its virtual methods "pure virtual":

virtual void Method() = 0;

The = 0 tells the compiler that this method must be overridden by a derived class, and might not have its own implementation.

If the class contains any non-pure virtual functions, then the compiler will assume that they have an implementation somewhere, and its internal structures (vtable and typeinfo) might be generated in the same object file as one of those; if those functions are not implemented, then the internal structures will be missing and you will get these errors.