链接器错误未定义符号

Linker Error undefined symbols C++

本文关键字:符号 未定义 错误 链接      更新时间:2023-10-16

我一直从链接器错误中得到很多麻烦。这是我最近买的一张。

Undefined symbols for architecture x86_64:
"XMLObject::~XMLObject()", referenced from:
  Hash::addFile(char*, XMLObject) in hash.o
  std::__1::__split_buffer<XMLObject, std::__1::allocator<XMLObject>&>::~__split_buffer() in hash.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

当我添加哈希表(.h和.cpp)时,我得到它。我真的不知道是什么原因导致这个错误。

void Hash::addObj(char* id, XMLObject num)
{
int index = hash(id);
if(hashTable[index]->identifier == "empty") // checks empty bucket
{
    hashTable[index]->identifier = id;
    hashTable[index]->files.push_back(num);
}
else // checks list
{
    bool check = false; // true if id word was found
    item* ptr = hashTable[index];
    while(ptr != nullptr)
    {
        if(ptr->identifier == id)
        {
            ptr->files.push_back(num);
            check = true;
            break;
        }
        ptr = ptr->next;
    }
    if(!check)
    {
        item* n = new item;
        n->identifier = id;
        n->files.push_back(num);
        n->next = nullptr;
        ptr = n;
    }
}
}

看起来您添加到您的项目hash.hhash.cpp,但该模块取决于另一个,可能是xmlobject.hxmlobject.cpp

解决方案:将这些文件也添加到项目中。