“Warning: Can't find linker symbol for virtual table for value XXX value” using GCC and GDB (CodeBlocks)

谁都会走 提交于 2019-12-05 04:43:44

Two errors that I can see:

strcpy(proovedor, "");  // No memory has been allocated to `proovedor` and
                        // it is uninitialised.

As it is uninitialised this could be overwriting anywhere in the process memory, so could be corrupting the virtual table.

You could change this to (in both constructors):

proovedor = strdup("");

Destructor uses incorrect delete on proovedor:

delete proovedor; // should be delete[] proovedor

As this is C++ you should considering using std::string instead of char*.

If you do not change to std::string then you need to either:

  1. Implement a copy constructor and assignment operator as the default versions are incorrect if you have a member variable that is dynamically allocated, or
  2. Make the copy constructor and assignment operator private to make it impossible for them to be used.

Another source of this same message is that gdb can get confused by not-yet-initialized variables. (This answers the question title, but not the OP's question, since a web search led me here looking for an answer.)

Naturally, you shouldn't have uninitialized variables, but in my case gdb attempts to show function local variables even before they are declared/initialized.

Today I'm stepping through another developer's gtest case and this message was getting dumped to output every time the debugger stopped. In this case, the variable in question was declared on ~line 245, but the function started on ~line 202. Every time I stopped the debugger between these lines, I received the message.

I worked around the issue by moving the variable declaration to the top of the function.

For reference, I am testing with gdb version 7.11.1 in QtCreator 4.1.0 and I compiled with g++ version 5.4.1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!