FrozenTarzan
FrozenTarzan

Reputation: 884

What could be the cause for runtime "can't find linker symbol for virtual table..." error in Qt?

This question was asked in similar ways multiple times, for example at stackoverflow or forum.qt.io or qtcentre.org. The problem is that this error message is so vague that one solution cannot be applied to another scenario. Most of the threads are dead in the middle of the discussion though :-(

So the complete error message that I get in my Qt application is:

can't find linker symbol for virtual table for "OneOfMyClasses"
value found "QString::shared_null" instead

The OneOfMyClasses changes depending on various things, the QString::shared_null stays the same for all errors that I get. Here is a screenshot of my logging console:

enter image description here

  1. Why is the font color pink, so who is printing this message?
  2. Why do I only see this message when I set a breakpoint and step through my code? This message does not appear when simply running the application.

The point where it happens is in this function in the source line right before the current position (yellow arrow):

enter image description here

So according to the message I stepped into m_pStateWidget->insertNavLabel(...) and the error message is printed somewhere in the constructors inside Qt related to the QString class. So I tried the following, which moves the problem away from this code location:

enter image description here

When doing this I get the same error message a few code lines below with another class name in the message, note that the QString::shared_null stays the same.

It appears to me that I have some sort of corrupted memory.

  1. How should I start investigating this issue? I'm afraid to change the code because this might hide the problem as described above.
  2. What's up with the QString::shared_null? I have found that others often see the same in their error messages.

Thank you for any hint or help! :-)

Edit: It's becoming really interesting now. I have stepped into every single function just right before the message is printed and I ended up with these error messages:

enter image description here

at this location:

enter image description here

When I navigate through the call stack in QtCreator the error is printed again and again everytime I select another function in the stack.

  1. Does this mean that the debugger is printing the message and that it is simply too stupid to resolve some sort of vtable stuff for me or does this mean that I have serious trouble going on?

Upvotes: 5

Views: 5859

Answers (2)

David Casper
David Casper

Reputation: 420

There are various threads on different websites where the

can not find linker symbol for virtual table

problem is discussed. Few explain why the problem exists, although some solutions are given to specific examples. Having experienced difficulty with this, I would like to share what I have learned.

First this error message only appeared for Linux builds, it did not show up for Windows builds.

In my case the problem was caused by a second call into a non-reentrant method from the same thread. Once I found the problem, it was easy to fix by using a static busy flag, and simply returning when busy was called a second time. In a nutshell that was the problem and solution. But how did I get into this mess?

Well the non-rentrant method was actually a Qt slot. Since I knew there was a possibility of the second call (actually an emit) being made from the first, the connect was set up with Qt::QueuedConnection. However, I later put up a splash screen QSplashScreen while the function was processing. Little did I realize that QSplashScreen::repaint() called QApplication::processEvents() which dispatched the second offending emit.

So I could have fixed the problem by removing the QSplashScreen and using a QLabel. However, while either works nicely in Windows, neither actually works in Linux, they put up a semi-transparent window and don't paint the contents (even repaint() and or processEvents() doesn't do it). So that is probably a Qt Linux bug, which is another story.

Upvotes: 2

Raams
Raams

Reputation: 177

Cause: Somewhere in your code , you might have overrun the actual memory

Example 1 :

int elmArray[10];
for(int i = 0; i < 20; ++i)
{
elmArray[i] = 0;
}

In the above case, actual array size is 10 but we are assigning values to the index beyond 10.

Example 2:

char* cpyString;

strcpy(cpyString , "TEST");

These scenarios might end up in writing the values into other objects. Mostly could corrupt the virtual table.This gives the above warning.

Fix: As you know, just correct the code as below. Example :

int elmArray[10];
for(int i = 0; i < 10; ++i)
{
elmArray[i] = 0;
}

char cpyString[10];
strcpy(cpyString , "TEST");

In your case seems like, you are assigning the QTString::shared_null to some uninitialized string.

Upvotes: 2

Related Questions