I've got an unusual request. Kotlin native has a v...
# kotlin-native
a
I've got an unusual request. Kotlin native has a very good perspective. The problem for myself and large part of scientific community is that we have to work with C++ libraries. Kotlin-Native does not have automatic interop with C++ libraries and there are few good reasons for it. Still, does anyone have experience with wrapping C++ libraries? If it is possible, could someone write a tutorial?
n
I guess you have two options. C wrapper, Objective C++ wrapper.
a
Does not seem to be the option 😞 It is easier to us SWIG wrapper and call it from JVM. By the way. I do understand why it is so hard to create C interop, but Objective-C seems to be almost the same, why is it possible?
n
Because you can mix C++ and Objective C in one file.
a
I mean why interop works with Objective C?
r
I believe Objective C doesn't have any metaptogramming capabilities, which makes it much easier target for interop than C++. FWIW, K/N is not the only language which ignores C++ interop completely, mostly for this very reason.
a
I am not language, but I also try to ignore it. Sadly, it is not always possible.
r
It is, yeah. I would love to see a tool like SWIG which is capable of wrapping C++ with C interface, even if it requires you to enumerate all possible template instantiations, but unfortunately I didn't found anything at that point.
o
@altavir could you please provide couple examples of C++ libs you’d like interop with
a
It is terrible, so be careful. Sadly, in particle physics nobody will even consider something which do not have at least limited interop with it.
Also https://geant4.web.cern.ch/, it written a bit better, but relies heavily on C++ inheritance.
g
SWIG supports quite a lot of languages. Maybe make sense invest to Kotlin code generation for SWIG