is there any good example or documentation for how...
# kotlin-native
i
is there any good example or documentation for how to use 3rd party library (particularly iOS
framework
provided by some vendor) in Kotlin Native?
And other another question as I understood
cinterop
will produce bunch some folder and klib file. How to include them into MP project with gradle as a build tool?
o
Have you checked docs on kotlinlang site, i.e. https://kotlinlang.org/docs/tutorials/native/interop-with-c.html
i
I think I made some progress, the issue that this link is describes the command line tool. I was looking into having 3rd party iOS framework how to integrate it to MPP with gradle build tool. I found this https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#cinterop-support
one issue though is how to provide where my 3rd party
framework
lives, getting error:
linkMainDebugFrameworkIos
ld: framework not found ...
s
You might have passed wrong linker options. Have you specified proper
-F
linker option in your Gradle build script or
.def
file?
i
@svyatoslav.scherbina Yeah I tried several options even with absolute path this is my build.gradle config
Copy code
fromPreset(presets.iosX64, 'ios') {
            compilations.main {
                kotlinOptions.freeCompilerArgs = ["-Xverbose-phases=linker"]
                outputKinds('FRAMEWORK')
                cinterops {
                    SharedLib {
                        // Def-file describing the native API.
                        // The default path is src/nativeInterop/cinterop/<interop-name>.def
                        defFile project.file("/Users/ivansavytskyi/Projects/{some path}/SharedLib.def")

                        // Package to place the Kotlin API generated.
                        packageName 'com.shopify.greeter'

                        // Options to be passed to compiler by cinterop tool.
                        compilerOpts '-I/Users/ivansavytskyi/Projects/{some path}/SharedLib.framework/Headers/'

                        linkerOpts '-F/Users/ivansavytskyi/Projects/{some path}/SharedLib.framework/SharedLib'
                    }
                }
            }
        }
def file is
Copy code
language = Objective-C
headers = SharedLib.h SharedLib-Swift.h
headerFilter = SharedLib.h SharedLib-Swift.h

compilerOpts = -framework SharedLib
linkerOpts = -framework SharedLib
if I remove 2 last lines from def (compilerOpts and linkerOpts), it seems like can find the framework but linker produces another error
Copy code
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$__TtC9SharedLib7Greeter", referenced from:
      objc-class-ref in combined.o
ld: symbol(s) not found for architecture x86_64
s
linkerOpts
with
-F
must be placed under
compilations.main {
instead of
SharedLib {
.
i
do I still need these lines in
def
file if I have linkerOpts and compilerOpts in gradle:
Copy code
compilerOpts = -framework SharedLib
linkerOpts = -framework SharedLib
I think I do, right?
ok I think I found the issue, my path for linker was including the
SharedLib.framework
but it needs to be parent path without it, like this
-F/Users/ivansavytskyi/Projects/{some path}/
s
do I still need these lines in
def
file if I have linkerOpts and compilerOpts in gradle:
Yes.
ok I think I found the issue, my path for linker was including the
SharedLib.framework
but it needs to be parent path without it, like this
-F/Users/ivansavytskyi/Projects/{some path}/
Linker opts should still be specified for the binary. Does it work now?