(It is a library for building languages: I use it ...
# kotlin-native
f
(It is a library for building languages: I use it with ANTLR and the Java target, I would like to use it also with ANTLR and the C++ target)
d
Are you familiar with JNI?
You just need to use JNI
Call
functions
f
I do not think JNI is what I need here. I am looking into creating a C++ library from Kotlin code to use it in C++ projects. Currently that code is for Kotlin JVM and I am considering transforming in Kotlin multi platform. JNI would be useful if I wanted to call C++ code from the JVM, which is not the case, or am I missing something?
d
You can use it both ways. I am not sure antlr exists outside of jvm.
I think your easiest way forward is using JNI, especially if your project contains multiple modules or significant amount of platform dependent code
env->CallObjectMethod(method, instance, args)
, this exists
f
Yes, ANTLR exists for several languages, including C++. It will generate C++ classes for a given grammar and it comes with a C++ runtime. I would like to have a multi platform library which works with ANTLR JVM and with ANTLR C++
d
Ah ok, then I cannot answer your question. I just know you can get a header file for your kotlin program and link against the compiled library, but I don't know how.
f
Thank you anyway for working with me on this one!
n
@ftomassetti - Did you know that Kotlin Native can generate a dynamic C library ( https://kotlinlang.org/docs/tutorials/native/dynamic-libraries.html )? Does the generated library have to be a C++ one?
f
It does not strictly have to be C++, however the code is object oriented
But C is a good start, thank you!