I’m trying to using latest FFIGEN (11.0.0) and almost latest Flutter 3.16.4 (dart 3.2.3)
This my my struct in C++
struct TestStruct {
const char *name;
bool isOnline;
uint8_t batteryLevel;
uint32_t timestamp;
};
And this is exported using
extern "C" struct TestStruct;
The problem is that every time I run FFIGEN it generates
final class TestStruct extends ffi.Struct {
external ffi.Pointer<ffi.Char> name;
@ffi.Int()
external int isOnline;
@ffi.Uint8()
external int batteryLevel;
@ffi.Uint32()
external int timestamp;
}
I have to manually change boolean entry to:
@ffi.Bool()
external bool isOnline;
I even tried to leave it and map int to bool later, but dart object is not correct.
Any ideas how to make ffigen understand bool field?
2
Answers
Answer to this issue was to include
#include <stdbool.h>
in this file. Even though everything worked from C++ code, dart was not aware of bool type.I was experiencing the same issue, and looking at the output there was a problem with a header file not being found. I added this line to my
.bashrc
file:export CPATH="$(clang -v 2>&1 | grep "Selected GCC installation" | rev | cut -d' ' -f1 | rev)/include"
Now the error is gone and booleans are properly generated.
This GitHub issue was useful.