Kotlin/Native with C++ libraries?


#1

Will Kotlin Native support call to C++ libraries or only C?


#2

hello, C++ ain’t have standard ABI, there is itanium ABI and M$ ABI


#3

Calls to C++ libraries are hard from point of view of creating apropriate semantical mappings, as many crazy advanced C++ libraries like Boost and their relatively sane easier to work with sibilings like STL are kind of languages on their own, so mapping them to Kotlin is pretty hard. OTOH, many libraries doing one clear thing (zlib, libpng, ffmpeg) do have C interface, so this shall be not much of a problem use them in Kotlin/Native.


#4

On the other hand some platform APIs have only C++ interface.
For example – gdiplus on windows.


#5

You could try going via SWIG: http://swig.org/Doc3.0/SWIGPlus.html# SWIGPLUS.HTML - either by extending SWIG to generate Kotlin; or you might be able to just have it generate its low-level C-to-C++ wrappers, ten is those directly from Kotlin. I’ve never actually used SWIG, though, I just know it exists.


#6

After several years of trying to write Windows applications using C++/MFC, I came to the conclusion in the late 1990’s that writing GUI applications was best left to ‘easier’ languages such as VB5/6 and (later) C#. Productivity is much better and performance is usually more than adequate.

Even if Kotlin Native did support C++ libraries, you’d probably end up writing C++ code with Kotlin syntax which, I suspect, would be an unpleasant experience. So, if GUI programming is your thing and coverage for your platform is already provided, I’d just stick with the JVM version of Kotlin for writing such applications.