I'm reading this documentation on how to create a ...
# kotlin-native
l
I'm reading this documentation on how to create a dynamic library with Kotlin, but it's not clear to me if it's possible to use the generated library from Kotlin itself, rather than from C. I want to build a dynamic library, written in Kotlin, that can be loaded on demand using
dlopen
. To be precise, I have a very large root library, let's call it A, and I then have a module B which links A and provides a normal endpoint (in practice, A is a language interpreter and B is the user interface code). What I want to do is to write a library C, which also links with A (but does not include it) which can dynamically be loaded from C when needed. Is this possible? C is a library that provides some extra functionality, and I can't include it in B since it in turn depends on some libraries that might not be available on the target system.
e
no. Kotlin/Native uses a closed-world compilation model - all the Kotlin code is assumed to be present in the same compilation
you can use cinterop between your dynamic library and the program which loads it, regardless of whether each is written in Kotlin or anything else that can interop with C
but a shared Kotlin library will exist in separate copies
l
@ephemient Thanks a lot for the information, and sorry for not replying with my appreciation earlier.
In my case, cinterop will be a bit of a hassle, since I would have to create a bridge between the two separate worlds. What I needed was a way to share kotlin objects between the main code and the library.