https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
b

basher

05/20/2019, 11:24 PM
Anyone have examples of a mpp framework that needs to dynamically link against another framework?
Trying to do this with various linker opts and having some difficulty
k

Kris Wong

05/21/2019, 12:10 AM
I don't have an example, but I have this working.
I can probably assist
b

basher

05/21/2019, 12:25 AM
Great! I’ve added
-framework <lib>
and
-F<path>
to the binary linker opts. Problem is that when I inspect the framework with otool -L, there’s no command added to dynamically link the framework. On top of that, I end up with all of the symbols from that framework in my main framework’s symbol table (causes lookup issues when launch the app)
k

Kris Wong

05/21/2019, 12:37 AM
Is this an objective C framework that you're consuming via cinterop?
b

basher

05/21/2019, 1:32 AM
It’s SQLite bundled into a framework. We use it In the main app, and I need it to link here as well
o

olonho

05/21/2019, 5:48 AM
Is main app in Kotlin?
s

svyatoslav.scherbina

05/21/2019, 6:41 AM
Is your Kotlin framework dynamic or static?
r

ribesg

05/21/2019, 8:40 AM
This may or may not help (group of 2 gists, don’t miss the link) https://gist.github.com/Ribesg/7a2b14841ad91d121bda24b6b1a7a054
b

basher

05/21/2019, 12:59 PM
The mpp framework is dynamic. Would like to dynamically link the SQLite framework
My current thought is that the linking happens for the klib, and then klib is packaged into a framework separately, which is why I don’t see the results of my ld flags using otool -l
k

Kris Wong

05/21/2019, 1:21 PM
you will need to link both frameworks into your app
either via pods or embedded binaries
s

svyatoslav.scherbina

05/21/2019, 2:07 PM
there’s no command added to dynamically link the framework.
On top of that, I end up with all of the symbols from that framework in my main framework’s symbol table (causes lookup issues when launch the app)
Could you clarify? It’s not clear how both can happen at the same time. What do you mean by “lookup issues”?
b

basher

05/21/2019, 2:38 PM
The symbol table for the k/n framework ends up with all of the symbols from the SQLite framework in it (maybe expected). But then because there’s no command added (I.e. otool -l doesn’t show any reference to SQLite), when something in the main app goes to reference a SQLite symbol, it sees it in the K/N framework’s symbol table and errors with a read failure (that symbol isn’t used by the framework, and the framework has no command to load the SQLite framework)
sees it in the K/N framework’s symbol table and errors with a read failure (that symbol isn’t used by the framework, and the framework has no command to load the SQLite framework)
This part is a bit speculative, but the error trace strongly suggests this is what’s happening (read error is accurate)
k

Kris Wong

05/21/2019, 3:55 PM
what is the actual error?
b

basher

05/21/2019, 3:58 PM
With this, it links fine (sqlite framework is built at $buildDir/sqlite3.framework). At runtime, it crashes when some other code goes to access a sqlite symbol (specifically a call to
sqlite3_collation_needed
) that the MPP framework does not use (read failure at 0x0)
Copy code
binaries {
    framework {
        embedBitcode = 'DISABLE'
        linkerOpts = ["-framework sqlite3", "-F$buildDir"]
    }
}
k

Kris Wong

05/21/2019, 4:04 PM
and you have embedded this framework in your app bundle?
b

basher

05/21/2019, 4:04 PM
yep
k

Kris Wong

05/21/2019, 4:04 PM
i've not seen anything like that before
b

basher

05/21/2019, 8:54 PM
ended up fixing all of my issues by just linking a local dylib (which properly adds the dylib load command to the framework) and then using install_name_tool to update it to a relative path that uses
@executable_path
👍 1