Is it possible to mix Kotlin and C code in the sam...
# kotlin-native
a
Is it possible to mix Kotlin and C code in the same klib library?
If so, how do I do that?
m
I wanted this too, but seems that currently it is not supported.
g
Maybe make sense to create a feature request. It's actually what you can do on JVM and mix Java and Kotlin on the same library
a
Where can I request it ?
r
Isn’t this what the
cinterop
tool is for? eg the gradle plugin can create an
interop
library to wrap your c code and then you can build a klib library that depends on it.
👍 1
s
You can do the following: 1) Compile your C source code to a static library. 2) Configure interop with this library. 3) Add it to
.klib
by specifying
staticLibraries = /path/to/static.a
in the
.def
file you use in 2)
👍 1
a
Worth a try
m
It works of course, but you cannot combine cinterop and your own kotlin code in single
.klib
. Only make kotlin lib depend on cinterop one - it works, but it is still two separate libs.
s
Yes, you can’t combine everything into single
.klib
, but what do you need this for?
a
Easy deployment of wrappers around a C library
s
And what does prevent one from publishing `.klib`s to local or remote (Maven) repository?
m
None, just for two
.klib
I have to assign two names - for example
libui.klib
for cinterop, and
libui-ktx.klib
for my wrappers.
s
Yes, this appears to be inconvenient. It still makes sense to create a feature request with discussed considerations included.