【问题标题】:Compile error in third party API - Visual Studio第三方 API 中的编译错误 - Visual Studio
【发布时间】:2020-10-22 13:45:55
【问题描述】:

我尝试使用一些哈希 API,但它给出了编译错误。我尝试了 2 个不同的哈希 API 和 2 个不同的 IDE 和编译器,但它给出了相同的错误。它看起来像一个链接器错误。通常存在“未解决的外部外部”或“未定义到”编译错误。如何修复编译错误?

test.cpp:

#include <iostream>
#include <string>
#include "xxHash-0.7.4/xxhash.h"

int main()
{
    const char test[] = "srgsdf";
    XXH64_hash_t seed = 545244;

    XXH64_hash_t test_xxhash = XXH64(test, strlen(test), seed);

    std::cout << test_xxhash;

    return 0;
}

错误列表:

LNK1120 -   unresolved externals    
LNK2019 -   unresolved external symbol _XXH64 referenced in function _main

Visual Studio 2019 - 16.6.2 上的 XXHash64: XXHash64 on Visual Studio

XXHash64 API on Code::Blocks - 20.03: XXHash64 API on Code::Blocks

Hash Library 在 Visual Studio 2019 - 16.6.2 上:Hash Library on Visual Studio

Hash Library on Code::Blocks - 20.03: Hash Library on Code::Blocks

【问题讨论】:

标签: c++ visual-studio compiler-errors codeblocks


【解决方案1】:

一个可能的原因是您的项目在其要编译的源文件列表中缺少xxhash.c。每个*.c 文件都成为一个目标文件,在最后阶段被链接。所以没有它,xxhash.c 中定义的符号就不会被创建。

解决此问题的另一种方法是在#include "xxhash.h" 之前发送#define XXH_INLINE_ALL。这将内联代码,就好像它存在于本地源文件中一样,因此,它不需要链接到另一个目标文件。内联也有利于小数据的性能,但会增加二进制大小。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-09
    相关资源
    最近更新 更多