Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 761
Lisa Avatar asked Nov 07 '09 16:11

Lisa


People also ask

What does undefined reference to Vtable mean?

In summary, there are three key causes of the "undefined reference to vtable" error: A member function is missing its definition. An object file is not being linked. All virtual functions have inline definitions.

What is undefined symbols for architecture x86_64?

Why Is the Undefined Symbols for Architecture x86_64: Error Happening? This error is happening due to the lack of included values inside the declared statements in your code. The browser is going to render the information incorrectly and show this error, especially if you are working with Main and Similarity tools.

What is a Vtable C++?

For every class that contains virtual functions, the compiler constructs a virtual table, a.k.a vtable. The vtable contains an entry for each virtual function accessible by the class and stores a pointer to its definition. Only the most specific function definition callable by the class is stored in the vtable.

What is undefined reference?

An “Undefined Reference” error occurs when we have a reference to object name (class, function, variable, etc.) in our program and the linker cannot find its definition when it tries to search for it in all the linked object files and libraries.


2 Answers

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.

like image 149
Mike Seymour Avatar answered Oct 17 '22 00:10

Mike Seymour


The class Obstacle needs a virtual destructor. Change the destructor definition to be:

virtual ~Obstacle();

The definition of a destructor also creates the vtable for a class with virtual functions. It also ensures that a delete of a derived class instance through a base class pointer does the right thing.

(copy of my answer to question What should I do with this strange error? which seems to be a duplicate.)

like image 8
janm Avatar answered Oct 17 '22 02:10

janm