Undefined Symbols "Vtable for ..." and "Typeinfo For..."

Why am I getting Undefined symbols ... typeinfo ... vtable with a virtual and concrete class?

The problem is you provide no implementation for Node::step(). If you truly wish for Node to have no implementation for step, then you should make it a purely virtual function Node::step(int count) = 0, thereby making Node an abstract class (you can not directly instantiate it). Otherwise, define an implementation for Node::step.

g++ undefined reference to typeinfo

One possible reason is because you are declaring a virtual function without defining it.

When you declare it without defining it in the same compilation unit, you're indicating that it's defined somewhere else - this means the linker phase will try to find it in one of the other compilation units (or libraries).

An example of defining the virtual function is:

virtual void fn() { /* insert code here */ }

In this case, you are attaching a definition to the declaration, which means the linker doesn't need to resolve it later.

The line

virtual void fn();

declares fn() without defining it and will cause the error message you asked about.

It's very similar to the code:

extern int i;
int *pi = &i;

which states that the integer i is declared in another compilation unit which must be resolved at link time (otherwise pi can't be set to it's address).

Undefined symbol: vtable

You forgot the class scope in your implementation of getQuality:

double Conductance::getQuality(std::unordered_set<node>& C, Graph& G) 
{
.....
}

Undefined reference to `typeinfo for class' and undefined reference to `vtable for class'

root::setSize isn't declared pure virtual, which means it must be defined. Presumably, it should be as pure as the other functions:

virtual void setSize(int) = 0;
^^^

If you're interested in the gory details of why you get that particular error: this compiler needs to generate the class's virtual/RTTI metadata somewhere and, if the class declares a non-pure, non-inline virtual function, it will generate it in the same translation unit as that function's definition. Since there is no definition, they don't get generated, giving that error.

Undefined reference to vtable

So, I've figured out the issue and it was a combination of bad logic and not being totally familiar with the automake/autotools world. I was adding the correct files to my Makefile.am template, but I wasn't sure which step in our build process actually created the makefile itself. So, I was compiling with an old makefile that had no idea about my new files whatsoever.

Thanks for the responses and the link to the GCC FAQ. I will be sure to read that to avoid this problem occurring for a real reason.

Undefined symbols for architecture x86_64 vtable

The linker prints those errors because definitions of your functions don't exist.
You declared 3 functions but you defined only the constructor.

Erasing the virtuals helps because then the linker don't need these functions.
With virtual, the linker uses them to create a vtable.

The error will come back if you use these functions in any other place in the program without defining them.

Undefined reference to vtable

You need to either make virtual void move(); a pure virtual function:

virtual void move() = 0;

or define Actor::move() for a base class

void Actor::move() 
{
// do something
}

undefined reference to `typeinfo and 'vtable

Ok, so apparently this all seems to be a compiler issue. This entire time I was using gedit as a text editor and g++ as a compiler, but when I switched over to code blocks it was working just fine.



Related Topics



Leave a reply



Submit