未知的警告源:“找不到虚拟表的链接器符号......”

时间:2011-01-18 07:50:21

标签: c++ eclipse gcc gdb warnings

几天后我在调试时收到警告消息。我找不到它的来源。我已经谷歌了,发现了类似的东西,因为我有一个静态变量。但是把它取出并没有改变任何东西。

这是main方法:

int main(int argc, char* argv[]) {
    if (argc != 2) {
        cout << "ERROR: Wrong amount of arguments!...\n"
             << endl;
        cout << "\n" << "Programm closed...\n\n" << endl;
    cin.ignore();
    exit(1);
    return 0;
    }

    cout << "argv[1] " << argv[1] << endl;

    GenericCommandConverter a(argv[1]);
    a.getCommandsFromCSV();

    cout << "\n" << "Programm finished...\n\n" << endl;

    return 0;
}

第一次出现的代码:

void GenericCommandConverter::getATCommandsFromCSV() {

    cout << "+++++++++++getCommandsFromCSV) started++++++++++++++" << endl;

    string filename_csv = "test.csv";
    string commands = "";
   int pos_start = 0;
    int pos_end = 0;
    int substrLength = 0;
    int separator_count = 0;

    char c;

    vector<string> lines;
    vector<string> commandList;
    vector<unsigned int> parameterPositionList;
    vector<vector<string> > linesSeparated;
    vector<vector<string> > part1_input;
    vector<vector<string> > part2_output;
    vector<map<vector<string> , vector<string> > > listedParameterMap;

    ifstream csvFile;
    csvFile.open(filename_csv.c_str(), ios_base::in);

    cout << "i'm starting getCommandsFromCSV()...\n" << endl;

    /**
     * STEP 1
     * Putting input text file into a string
     */
    if (csvFile.is_open()) {
        while (!csvFile.eof()) { // <------- warning occurs here!
                csvFile.get(c);
            commands += c;
    }

...

}

警告:

[New Thread 2000.0x11bc]
warning: can't find linker symbol for virtual table for
`std::less<std::vector<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::allocator<std::basic_string<char, 
std::char_traits<char>,     std::allocator<char> > > > >' value

有谁知道为什么会这样?每条线都有它,直到它开始。它完全填满了控制台,无法进行调试。 另一个可能是独立模式的重要信息,不会显示此错误。

我真的很感激一些帮助!

编辑:标题文件

#ifndef CommandConverter_H_
#define CommandConverter_H_

#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <iosfwd>
#include <map>
#include <vector>
#include <cstdio>

using namespace std;

class CommandConverter {
public:
    CommandConverter(char* file);
    virtual ~CommandConverter();

    void printConvertedTraceByPage(vector<string> lines);

    map<string, vector<map<vector<string> , vector<string> > > > csvMap;
    static const int MAX_SIZE = 5;

    void getATCommandsFromCSV();
    string readTxtFile();
    vector<string> splitIntoLines(const char* trace);
    vector<string> convert(vector<string> fileInLines);

    bool commandAvailable(const char* l, int pos, const char* s);
    void error(const char* p, const char* p2);
    void printCSV();

    // opened in constructor; closed in destructor
    ifstream myfile;
    string filename;
    string trace_raw;
};

#endif /* CommandConverter_H_ */

2 个答案:

答案 0 :(得分:10)

该消息来自gdb/gnu-v3-abi.c中的此代码:

static struct type *
gnuv3_rtti_type (struct value *value,
                 int *full_p, int *top_p, int *using_enc_p)
{
...
  /* The symbol's demangled name should be something like "vtable for
     CLASS", where CLASS is the name of the run-time type of VALUE.
     If we didn't like this approach, we could instead look in the
     type_info object itself to get the class name.  But this way
     should work just as well, and doesn't read target memory.  */
  vtable_symbol_name = SYMBOL_DEMANGLED_NAME (vtable_symbol);
  if (vtable_symbol_name == NULL
      || strncmp (vtable_symbol_name, "vtable for ", 11))
    {
      warning (_("can't find linker symbol for virtual table for `%s' value"),
               TYPE_NAME (values_type));
      if (vtable_symbol_name)
        warning (_("  found `%s' instead"), vtable_symbol_name);
      return NULL;
    }

现在,我很确定std::less首先不应该有一个虚拟表,所以GDB很可能会感到困惑。

您需要验证最新GDB存在问题,并提交错误。

由于这只是最近才开始的,您是否升级了GCC,GDB或更改了编译标志?

答案 1 :(得分:1)

回答问题标题,但不是OP的问题(因为网络搜索引导我在这里):同一消息的另一个来源是gdb可能会被尚未初始化的变量搞糊涂。

当然,你不应该有未初始化的变量,但在我的情况下,gdb尝试在声明/初始化之前显示函数局部变量。

今天我逐步介绍了另一个开发人员的gtest案例,每次调试器停止时,此消息都会被转储到输出。在这种情况下,有问题的变量在〜第245行声明,但是函数在第202行开始。每次我在这些行之间停止调试器时,我收到了消息。

我通过将变量声明移到函数顶部来处理这个问题。

供参考,我在QtCreator 4.1.0中使用gdb版本7.11.1进行测试,并使用g ++版本5.4.1进行编译