Hey loving kotlin native. I was wondering if there...
# kotlin-native
a
Hey loving kotlin native. I was wondering if there was any workaround to the problems with C++ interop. I read earlier this morning that back in march of 2018 on the kotlin forums, contributer msink had stated "Kotlin/Native does not support C++ libraries, only C and Objective-C. It’s possible in theory, but hard to implement, and currently no plans for this." I was wondering what the plans are now. My static library has simple c++ use but I can easily change it to C since I'm using flex/bison to generate some C++ code for lexer and parser code, it seems to work better with C. I only have it generating C++ code because I would like to utilize C++ classes for what I would think is better interop from kotlin to C++. Is there any way I can have a C++ lib in a kotlin native project or do I need to pretty much convert my currently minimal C++ library. However the generated code is C++ but flex/bison can always regen in C.
And I do understand that there is no documentation on c interop with c++ classes, but considering that gcc/g++ treat classes and structs the same (or as I've heard) I would think that perhaps kotlin native would be able to bind a c++ class the same way as a c struct right? Except I also see the kotlin native has no recognition of encapsulation which C structs lack
k
I can tell you K/N needs C, whether you regen as C, or create a simple C shim API
b
m
You can use C interop with C++ youll just need to create wrapping functions in C++ that are marked with extern "C"
a
What about using stl classes like vector or sstream or iostream. Is that out of the question as well?
m
You cant use them in the C API but you could use them internally. If you need to send state through to kotlin but only are going to use it inside of your C++ library and just need kotlin to pass it you can wrap it in void*
a
Hmm I can give that a try actually