Hello, I'm wonder how can I have something like Ja...
# kotlin-native
a
Hello, I'm wonder how can I have something like Java JNI but for Kotlin? How do I generate a c/c++ header from Kotlin code? I have a JVM project (not multiplatform) where I would like to create a small Kotlin class to genenrate the c++ header then I will write C++ code to fulfill my needs. Is that doable?
h
Biggest question is, why javah does not work with byte code. How do other jvm language generate headers? But for Kotlin, I guess, ksp sounds doable, just filter the
native
classes and create the c code. Do you have a C code generator lib in mind?
b
I usually just write java interfaces and generate from that. Then use ij java to kt concerter to get rid of those
Oh and you can implement native side in kotlin native too!
a
@Big Chungus When I said "I will write C++ code to fulfill my needs" It's essentially writing C++ code that will use a c++ library that is not available only in C++. So would this scenario still be a candidate to use Kotlin Native? I'm extremely new to KN
@hfhbd I'm new to this so anything that works I'll use basically, dont have any C code generator lib in mind.
b
Ah, no. Kotlin native does not support cpp interop at the moment. You can hack it via c bindings, but i wouldn't recommend it
a
Ok then my best option would be to use a Java Class + JNI yes ? @Big Chungus
b
That would be my recommendation
Or alternatively use kotlin external declarations on jvm and write c headers yourself (they're really not that hard once you've seen some examples)
I personally prefer the latter, but it is a bit more involved to get used to