CMockery编译未知类型名称“ jmp_buf”

时间:2019-04-10 13:41:07

标签: cmake cmockery

我正在尝试将单元测试框架cMockery添加到我的C项目中。我已经将cMockery下载并安装到全局包含路径中。但是在源文件中的#include <cmockery.h>之后,cmake会引发以下问题。如果我也使用cMocka,似乎也会抛出同样的事情。我是否缺少一些包裹?

编辑:Google搜索"/usr/include/google/cmockery.h:365:8: error: unknown type name ‘jmp_buf’"的结果恰好是 0个结果(现在有1个结果指向此问题)。搜索unknown type name 'jmp_buf'只能说明它是什么。不是如何解决它,或者为什么它会在cmockery内部发生。

/usr/bin/cmake --build /home/.../data-structures-c/cmake-build-debug --target data_structures_c -- -j 3
Scanning dependencies of target data_structures_c
[ 50%] Building C object CMakeFiles/data_structures_c.dir/main.c.o
In file included from /home/.../data-structures-c/main.c:3:
/usr/include/google/cmockery.h:365:8: error: unknown type name ‘jmp_buf’
 extern jmp_buf global_expect_assert_env;
        ^~~~~~~
make[3]: *** [CMakeFiles/data_structures_c.dir/build.make:63: CMakeFiles/data_structures_c.dir/main.c.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/data_structures_c.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/data_structures_c.dir/rule] Error 2
make: *** [Makefile:118: data_structures_c] Error 2

OS:Manjaro Archlinux

Cmake,make,gcc,g ++已全部安装。

我的CMakeList.txt也很标准,只有一个c源代码

cmake_minimum_required(VERSION 3.12)
project(data_structures_c C)
set(CMAKE_C_STANDARD 99)
add_executable(data_structures_c main.c)

我想知道如何解决此问题以便编译我的代码。

1 个答案:

答案 0 :(得分:2)

根据google/cmockery.h标头开头的注释:

/*
 * These headers or their equivalents should be included prior to including
 * this header file.
 *
 * #include <stdarg.h>
 * #include <stddef.h>
 * #include <setjmp.h>
 *
 * This allows test applications to use custom definitions of C standard
 * library functions and types.
 */

之前(包括此标题),应包括以下标题:

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

只有在包含这些内容之后,才可以

#include <google/cmockery.h>