【问题标题】:Error building project with make command, use of undeclared identifier '__compar_fn_t'使用 make 命令构建项目时出错,使用未声明的标识符“__compar_fn_t”
【发布时间】:2021-11-10 00:43:36
【问题描述】:

我正在尝试构建 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

【问题讨论】:

标签: c makefile redis build


【解决方案1】:

RedisBloom 项目使用实现细节 (__compar_fn_t) 将 cmpHeapBucket 的函数签名从快捷签名转换为正确的签名。依赖这样的实现细节是不好的,而且往往不是很便携。

我建议您下载最新版本的 RedisBloom。我为它创建了a patch,它现在已合并到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;
}

【讨论】:

  • 感谢您的修复!
  • @dses 不客气,很高兴它成功了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多