I am trying to add unit testing framework cMockery to my C project. I have downloaded and installed the cMockery into global include path. But after #include <cmockery.h>
in my source file, cmake throws the following issue. It seems the same thing will be thrown if I use cMocka
as well. Am I missing some packages?
Edit: Google search for "/usr/include/google/cmockery.h:365:8: error: unknown type name ‘jmp_buf’"
returned exactly 0 results (Now 1 result pointing to this question). As well as searching for unknown type name 'jmp_buf'
only explains what is it. Not how to fix it or why does it happen inside 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++ all installed.
My CMakeList.txt
is also very standard, bare minimum with a single c source
cmake_minimum_required(VERSION 3.12)
project(data_structures_c C)
set(CMAKE_C_STANDARD 99)
add_executable(data_structures_c main.c)
I would like to know how to solve this issue in order to compile my code.
According to the comments at the beginning of google/cmockery.h header:
/*
* 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.
*/
Before including this header, one should include following headers:
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
Only after these includes it is allowable to
#include <google/cmockery.h>