【问题标题】:"undefined reference to `_cmocka_run_group_tests'" when running sample CMocka test运行示例 CMocka 测试时“未定义对 `_cmocka_run_group_tests' 的引用”
【发布时间】:2015-07-08 20:39:02
【问题描述】:

我安装了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

我错过了什么?

【问题讨论】:

    标签: c gcc linker undefined-reference cmocka


    【解决方案1】:

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

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

    【讨论】:

    猜你喜欢
    • 2017-07-20
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 2018-05-04
    • 2016-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多