gpt4 book ai didi

c - "undefined reference to ` _cmocka_run_group_tests '"运行示例 CMocka 测试时

转载 作者:太空狗 更新时间:2023-10-29 15:35:25 24 4
gpt4 key购买 nike

我安装了 CMocka testing framework并尝试了 sample code :

#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>

/* A test case that does nothing and succeeds. */
static void null_test_success(void **state) {
(void) state; /* unused */
}
int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(null_test_success),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}

但是当我尝试编译时出现以下错误:

$ gcc -o Tests tests.c
/tmp/ccbwAXrr.o: In function `main':
tests.c:(.text+0x5e): undefined reference to `_cmocka_run_group_tests'
collect2: error: ld returned 1 exit status

我错过了什么?

最佳答案

包含头文件提供了函数的前向声明。要获取函数定义,您需要链接库。

您可以使用 -l 选项和 gcc 链接到所需的库。您可能还需要使用 -L 选项来提供库的路径。

关于c - "undefined reference to ` _cmocka_run_group_tests '"运行示例 CMocka 测试时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29945791/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com