https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

siraf

10/31/2023, 1:41 PM
Hi all, is it possible to somehow`import` the code from .c and .h files into one class inside shared kmm library and use it in Kotlin code?
o

Oleg Yukhnevich

10/31/2023, 1:55 PM
You will need to configure JNI/Panama/JNA for jvm and cinterop for native - this is the only way right now But what specifically do you want? cinterop for multiplatform?
s

siraf

10/31/2023, 1:58 PM
there was a library previously installed by Cocoapods and imported in kotlin file by
*import* cocoapods.libraryName.*
. We have removed Cocoapods from project and downloaded needed .h and .c files directly(by cloning the library and moving them into the project). Now we are trying to call their functions somehow but it always says
Unresolved reference...
. I don’t have Kotlin background so this is a bit confusing..
o

Oleg Yukhnevich

10/31/2023, 2:03 PM
Ah, so you just need it for K/N Then you need to configure cinterop to genera bindings from .h files, though not sure that there is a simple way to include .c files It’s hard for me to help here, as I don’t know how cocoapods integration works and how to replace it
l

Landry Norris

10/31/2023, 2:29 PM
You can use cinterop to tell the compiler which headers to read and where to find libraries. You'll generally want to compile your C project (Ideally statically if possible) first and link against the binary. For small bits of C code, you can add '---' to the end of the def file and everything after will be treated as a C file and compiled/linked for you.