c++ - 链接器错误 undefined symbol C++

标签 c++ linker-errors

链接器错误给我带来了很多麻烦。这是我最近得到的。

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

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

关于c++ - 链接器错误 undefined symbol C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23425430/

相关文章:

成员变量的C++类型名

c++ - 有没有办法用混合字符和 "strings"初始化数组

c++ - 从 OpenGL 中的纹理采样是黑色的

c++ - 链接错误 LNK1120 和 LNK2019 - "unresolved external symbol _main"

c++ - 从 C++ 包装器调用导出的 C 函数时出现错误 LNK2028

c++ - 什么是 undefined reference /未解析的外部符号错误以及如何修复它?

c++ - 无法修复 C++ 中的链接器错误

c++ - 如何实现自己的混合功能?

c - 链接器错误 - typedef 结构

c++ - 你如何模拟在 C++ 中使用 RAII 的类