I got a little bit tired of banging my head agains...
# kotlin-native
a
I got a little bit tired of banging my head against C++ and decided to at least try to do a kotlin wrapper. The library I am using is in C++, but seems to have plain c interfaces. I managed to create interop file, but the header depends on C++ stdlib files like
cmath
,
memeory
etc. How can I link them as well?
n
Remember that Kotlin Native doesn't have C++ interop support. Only C interop support is provided. All C++ dependencies would need to be handled separately from the Kotlin Native project.
These C++ dependencies would need to be converted to C dependencies in order for Kotlin Native's C Interop system to handle them (aka satisfy C linking requirements).
Which Kotlin version are you using? Kotlin versions < 1.5 use a linker (old one) that isn't very strict, which can in some cases make linking easier. If Kotlin 1.5 or later is used then a strict linker (new one) is used, which is known to cause some major issues in some cases that doesn't occur with the old linker. With the Linux ARM targets you are more likely to encounter linking issues when using Kotlin 1.5 than with the linuxX64 target for example.
a
It is 1.5 and mingw target. The library I am wrapping is c-style c++. So if I just could work around these stdlib problems with static linking, it would be ok.
m
So problem is in static linking on Windows? Should be just linkerOpts( "-L${msys2.resolve("${targetName}/lib")}", "-Wl,-Bstatic", "-lstdc++", "-static", ... See sample in https://github.com/msink/hello-curl
a
@msink thanks a lot it looks like the thing I was looking for, I will try to do that. Currently I am doing wrapper in C++, but avoided C++ for far too long and it is too frustrating after Java and Kotlin.
u
@altavir Have you successfully completed the wrapper code? I encountered the same annoying situation. I think I would be very grateful if I could see some examples of your successful code :)
a
Nope, C++ is out of reach for now.