使用make命令构建项目时出现错误,使用未声明的标识符“__compar_fn_t”。

3

我正在尝试构建RedisBloom,在运行make命令后,我收到以下错误信息。

clang -dynamic -fcommon -g -ggdb -Wall -Wno-unused-function -g -ggdb -O2 -fPIC -std=gnu99 -D_GNU_SOURCE -I/Users/john/workspace/RedisBloom/contrib -I/Users/john/workspace/RedisBloom -I/Users/john/workspace/RedisBloom/src -I/Users/john/workspace/RedisBloom/deps/t-digest-c/src  -c -o /Users/john/workspace/RedisBloom/src/topk.o /Users/john/workspace/RedisBloom/src/topk.c
/Users/john/workspace/RedisBloom/src/topk.c:223:50: error: use of undeclared identifier '__compar_fn_t'
    qsort(heapList, topk->k, sizeof(*heapList), (__compar_fn_t)cmpHeapBucket);
                                                 ^
1 error generated.
make: *** [/Users/dsesma/eclipse-workspace/RedisBloom/src/topk.o] Error 1

我正在使用macOS Big Sur操作系统


1
有一个关于这个特定错误的问题。https://dev59.com/K0zSa4cB1Zd3GeqPqu_i,但除非你想自己更改代码,否则你可能需要报告一个错误。 - Effie
1个回答

2
RedisBloom项目使用一个实现细节(__compar_fn_t)来将函数cmpHeapBucket的签名从快捷签名转换为正确的签名。依赖此类实现细节是不好的,往往不太可移植。
我建议您下载最新版本的RedisBloom。 我对其进行了补丁,现在已合并到master中,该补丁执行以下操作:
src/topk.c中修复:
// make the compare function have the correct signature:
int cmpHeapBucket(const void *tmp1, const void *tmp2) {
    const HeapBucket *res1 = tmp1;
    const HeapBucket *res2 = tmp2;
    return res1->count < res2->count ? 1 : res1->count > res2->count ? -1 : 0;
}

HeapBucket *TopK_List(TopK *topk) {
    HeapBucket *heapList = TOPK_CALLOC(topk->k, (sizeof(*heapList)));
    memcpy(heapList, topk->heap, topk->k * sizeof(HeapBucket));

    //                      now, no cast is needed below:
    qsort(heapList, topk->k, sizeof(*heapList), cmpHeapBucket);
    return heapList;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接