Kotlin classes aren't being generated for blank C ...
# kotlin-native
n
Kotlin classes aren't being generated for blank C Structs. Is this normal behaviour for K/N C interop? Below is the definition of the structs from the gpiod.h file:
struct gpiod_chip;
struct gpiod_line;
struct gpiod_chip_iter;
struct gpiod_line_iter;
struct gpiod_line_bulk;
Presumably I can get around this by passing around a
CPointer<*>
type, and converting it via the
reinterpret
function in the relevant function, e.g.:
private fun toggleGpioPin(chip: CPointer<*>, line: CPointer<*>) {
var value = 0
while (true) {
sleep(1u)
value = if (value == 0) 1 else 0
if (gpiod_line_set_value(line.reinterpret(), value) == -1) {
gpiod_chip_close(chip.reinterpret())
throw IllegalStateException("Cannot set value for GPIO pin")
}
}
}
a
iirc you can import them as as cname structs (e.g.
import cnames.structs.gpiod_chip
). cname structs are unrelated to cinterop, and the Kotlin compiler will just pretend that there's a struct with that name, but it might fail at runtime https://kotlinlang.org/docs/native-c-interop.html#forward-declarations
👍 1
n
Would the, might fail at runtime be applicable regardless of whether the library is statically or dynamically linked?
After trying out what you have suggested the program didn't fail at runtime 😄 .
a
d'oh, I'm misremembering then
did it help though, importing them with
cnames.structs
?
👌 1