Include required headers in CMocka header file
As stated in the cmocka.h
header file, some headers file SHOULD be included before.
First, the word MUST should be used in the documentation as not including those files make the compilation fail.
Second, why not including those files within cmocka.h
? Is it needed for mocking to not include them within CMocka ?
Source code example
#include <cmocka.h>
int main(void)
{
return 0;
}
Compilation errors
Compilation done using GCC:
> gcc ../test/main.c
In file included from ../test/main.c:2:
/usr/include/cmocka.h:2079:11: error: unknown type name ‘size_t’
const size_t number_of_tests;
^~~~~~
/usr/include/cmocka.h:2112:8: error: unknown type name ‘jmp_buf’
extern jmp_buf global_expect_assert_env;
^~~~~~~
/usr/include/cmocka.h:2138:11: error: unknown type name ‘size_t’
const size_t number_of_values, const int count);
^~~~~~
/usr/include/cmocka.h:2142:11: error: unknown type name ‘size_t’
const size_t number_of_values, const int count);
^~~~~~
/usr/include/cmocka.h:2176:11: error: unknown type name ‘size_t’
const size_t size, const int count);
^~~~~~
/usr/include/cmocka.h:2180:11: error: unknown type name ‘size_t’
const size_t size, const int count);
^~~~~~
/usr/include/cmocka.h:2197:26: error: unknown type name ‘size_t’
size_t rlen,
^~~~~~
/usr/include/cmocka.h:2197:26: note: ‘size_t’ is defined in header ‘<stddef.h>’; did you forget to ‘#include <stddef.h>’?
/usr/include/cmocka.h:1:1:
+#include <stddef.h>
/*
/usr/include/cmocka.h:2197:26:
size_t rlen,
^~~~~~
/usr/include/cmocka.h:2213:33: error: unknown type name ‘size_t’
const size_t size, const char* const file,
^~~~~~
/usr/include/cmocka.h:2216:37: error: unknown type name ‘size_t’
const size_t size, const char* const file,
^~~~~~
/usr/include/cmocka.h:2226:11: error: unknown type name ‘size_t’
const size_t number_of_values, const char* const file, const int line);
^~~~~~
/usr/include/cmocka.h:2229:11: error: unknown type name ‘size_t’
const size_t number_of_values, const char* const file, const int line);
^~~~~~
/usr/include/cmocka.h:2231:26: error: unknown type name ‘size_t’
void* _test_malloc(const size_t size, const char* file, const int line);
^~~~~~
/usr/include/cmocka.h:2232:38: error: unknown type name ‘size_t’
void* _test_realloc(void *ptr, const size_t size, const char* file, const int line);
^~~~~~
/usr/include/cmocka.h:2233:26: error: unknown type name ‘size_t’
void* _test_calloc(const size_t number_of_elements, const size_t size,
^~~~~~
/usr/include/cmocka.h:2233:59: error: unknown type name ‘size_t’
void* _test_calloc(const size_t number_of_elements, const size_t size,
^~~~~~
/usr/include/cmocka.h:2246:40: error: unknown type name ‘size_t’
const size_t number_of_tests);
^~~~~~
/usr/include/cmocka.h:2248:46: error: unknown type name ‘size_t’
const size_t number_of_tests);
^~~~~~
/usr/include/cmocka.h:2253:35: error: unknown type name ‘size_t’
const size_t num_tests,
^~~~~~
/usr/include/cmocka.h:2260:47: error: unknown type name ‘va_list’
void vprint_message(const char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
^~~~~~~
/usr/include/cmocka.h:2260:47: note: ‘va_list’ is defined in header ‘<stdarg.h>’; did you forget to ‘#include <stdarg.h>’?
/usr/include/cmocka.h:1:1:
+#include <stdarg.h>
/*
/usr/include/cmocka.h:2260:47:
void vprint_message(const char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
^~~~~~~
/usr/include/cmocka.h:2261:45: error: unknown type name ‘va_list’
void vprint_error(const char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
^~~~~~~
/usr/include/cmocka.h:2261:45: note: ‘va_list’ is defined in header ‘<stdarg.h>’; did you forget to ‘#include <stdarg.h>’?
Edited by Ghost User