Kotlin-native: Shared library without runtime

Created on 8 Oct 2018  路  7Comments  路  Source: JetBrains/kotlin-native

Hi there.
I've just tried to create 2 shared libraries and use them in one process. So I got a lot of exceptions like this:

objc[6317]: Class KotlinBase is implemented in both pathToLib/bin/macos_x64/libdrillagent.dylib (0x10d2df9a8) and anotherPathToLib/bin/macos_x64/libdrillagent.dylib (0x115885708). One of the two will be used. Which one is undefined.

Any change to escape this??? Can I create the second shared library without kotlin/n runtime?

Most helpful comment

So you use -produce shared option? Runtime must be linked into the library, and objects between two are not compatible.

All 7 comments

So you use -produce shared option? Runtime must be linked into the library, and objects between two are not compatible.

Yes, I use -produce dynamic. So I created 2 shared libraries... Finally I got this exception

2018-10-09 23:12:14.977 java[10611:294564] * Terminating app due to uncaught exception 'NSGenericException', reason: 'Only one Kotlin framework can be loaded currently'

This is macOS limitation, as frameworks are dynamic libraries as well, and we can only support one framework at the moment, and check that at the runtime. For case of C interop this limitation may be lifted.

For case of C interop this limitation may be lifted.

Unfortunately this is not possible currently: Kotlin/Native runtime contains a few named Objective-C classes that may be required even when the produced binary is not a framework. So it is not possible to load 2 runtimes even when -produce dynamic, otherwise these classes would clash.

Oh... Do we have any workarounds for this? So, I found the beautiful purposes for using K/N in my tool. I produce JVMTI agent. It works perfectly without any c/c++ code... But my final goal is to create a plugin oriented arch. where each plugin consist a shared library and this library can attach to live JVM. JVM can attaches a lot of agents..

You can try to rebuild Kotlin/Native with these checks disabled, see e.g. https://github.com/JetBrains/kotlin-native/blob/master/runtime/src/main/cpp/ObjCExport.mm#L381

There is a chance that everything would work fine if you don't use Objective-C interoperability at all (neither does any of the libraries you depend on).

Thanks, I'll try it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brettwillis picture brettwillis  路  4Comments

alastaircoote picture alastaircoote  路  3Comments

msink picture msink  路  4Comments

benasher44 picture benasher44  路  4Comments

SBNTT picture SBNTT  路  4Comments