Kotlin interop with C++


I plan to mess around with a game engine project, for whom I use opengl with C++, as well as Bullet Physics, which is also written in C++. Note I’m not doing any libgdx (because I found its workflow terrible), and the java version of Bullet is pretty much abandoned.

However, I’d like to use Kotlin as a scripting API.

Can I do that? If so, how?

And - given I use opengles - can I compile that to Android as well?

Thanks for the info.


I don’t see why any of what you plan would not be possible. I would take a look at https://github.com/JetBrains/kotlin-native/blob/master/INTEROP.md to interface with any C/C++ libraries. And I think you should be able to compile to android. The only real problem you might have, is the early stage of Kotlin Native. There were a few discussions here about tools for it as the only way to debug it so far is CLion which has no free version and does not support gradle and I am not sure how to debug Kotlin native while not running on windows/mac/linux.
That being said, you can still use gradle (all the documentation is for gradle as well). You might just run into a few problems, with not yet existing tools, etc. Kotlin native is still in version 0.6 if I am not wrong, so still early development, but I am sure JetBrains would love to hear whatever you find using it :slight_smile:


Thanks for the reply.
I might interop with Java then using JNI and then interop Kotlin With Java as intended :smiley: A bit of a hassle, but that’s that.
Technically I could use Java (or just C++ all along lol) but I like the fashion Kotlin uses to write code and I never liked the verboseness of Java and the ease of writing errors in C++.


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.


How about interface Java with C++ and then use Kotlin that way?
AFAIK Java has JNI with whom I can interop with C++ and Kotlin can easily interop with Java,
Am I on the right track?


@agiro I would love to see what you accomplish so far right now with your project, I’m playing around with something similar, but using Kotlin native directly (nothing of JNI), I’m progressing slowly because the lack of documentation (I mean user generated content in relation of Kotlin native).

Basically I’m playing with GLFW for windowing and user input, then OpenGL for the render engine (that is where I’m stuck right now) and later jump onto OpenAL and Bullet to have a minimal but functional prototype of game engine.


@agiro check it out, I’ve started working on the opengl tutorials and porting to kotlin https://github.com/norman784/kotlin-native-opengl-tutorial, I still have issues just like in the tutorial 5 (with the textures, they are not rendering), also the tutorial 3 (matrices) are WIP because I didn’t find an alternative to GLM.