Been looking through some of the mappings generate...
# kotlin-native
n
Been looking through some of the mappings generated for the libudev library:
Copy code
public fun udev_list_entry_get_by_name(list_entry: kotlinx.cinterop.CValuesRef<cnames.structs.udev_list_entry>?, @kotlinx.cinterop.internal.CCall.CString name: kotlin.String?): kotlinx.cinterop.CPointer<cnames.structs.udev_list_entry>? { /* compiled code */ }

public fun udev_list_entry_get_name(list_entry: kotlinx.cinterop.CValuesRef<cnames.structs.udev_list_entry>?): kotlinx.cinterop.CPointer<kotlinx.cinterop.ByteVar /* = kotlinx.cinterop.ByteVarOf<kotlin.Byte> */>? { /* compiled code */ }

public fun udev_list_entry_get_next(list_entry: kotlinx.cinterop.CValuesRef<cnames.structs.udev_list_entry>?): kotlinx.cinterop.CPointer<cnames.structs.udev_list_entry>? { /* compiled code */ }

public fun udev_list_entry_get_value(list_entry: kotlinx.cinterop.CValuesRef<cnames.structs.udev_list_entry>?): kotlinx.cinterop.CPointer<kotlinx.cinterop.ByteVar /* = kotlinx.cinterop.ByteVarOf<kotlin.Byte> */>? { /* compiled code */ }
There doesn't appear to be a definition in any of the knm files for
udev_list_entry
(a C struct), however
cnames.structs.udev_list_entry
does exist but its definition doesn't seem to appear in any of the knm files which is strange.
m
In
libudev.h
it just declared as opaque handle
struct udev_list_entry;
, and defined in
libudev-internal.h
So if you want to access it's fields - add
libudev-internal.h
to headers in
.def
file
n
Does the cnames.structs.x indicate that there is a Struct used in the C lib which the cinterop tool cannot find the definition for?
The libudev-internal.h file doesn't exist in the libudev-dev deb package.
m
Of course, it is internal, but available in libudev (now part of systemd) sources on github.
Well, sorry, I messed something - it isn't available in header, just in C source And seems that implementation is different in different versions.
n
Presumably Kotlin Native only supports C interop via header files. Would be good if the cinterop tool supported C source files, which would likely resolve the current problem.
Looks as though I will have to look at an alternative C library (eg libusb - https://libusb.info/ ).
o
it’s forward declaration, and can be used as such. It corresponds to
struct Foo
in C header, and is common way if declaring opaque handle type. It could be used from K/N same way as from C.
👍 1
interop can use declarations from .h or .c files, it doesn’t care, and you can add it to headers, or copy-paste structure declaration to .def file after
---
.
👍 1