How do I include C binaries in a kotlin multiplatf...
# multiplatform
j
How do I include C binaries in a kotlin multiplatform library? Currently the app that consumes the library all needs these as co-dependencies
I guess, it's. Oh, for a library, you need to copy them in your framework bundle
j
Hey again @François, doesn't say anything about where to put .so files etc there 🙂
What is the framework bundle? Will that work for all targets?
f
You need to do it manually, but it depends on what kind of framework you're using
are you building a xcframework?
j
I think so. How can I check?
We need Android, iOS and JVM targets. The other targets are kind of just hanging in there
f
Adding dynamic libs for a library targeting iOS is a bit tricky.
First, you need to link your library to your library. For exemple:
Copy code
val defFilRootPath = "iosDeps"
    val frameworkRootPath = "$projectDir/iosDeps/Carthage/Build"
    val armSimArch = "ios-arm64_x86_64-simulator"
    val armDevArch = "ios-arm64"
 iosSimulatorArm64 {
        compilations.getByName("main") {
            val KeePassKit by cinterops.creating {
                // Path to .def file
                defFile("$defFilRootPath/KeePassKit.def")
                compilerOpts("-framework", "KeePassKit", "-F$frameworkRootPath/KeePassKit.xcframework/$armSimArch")
                extraOpts += listOf("-compiler-option", "-fmodules")
            }
            val KissXML by cinterops.creating {
                defFile("$defFilRootPath/KissXML.def")
                compilerOpts("-framework", "KissXML", "-F$frameworkRootPath/KissXML.xcframework/$armSimArch")
                extraOpts += listOf("-compiler-option", "-fmodules")
            }
        }

        binaries.all {
            // Tell the linker where the framework is located.
            linkerOpts(
                "-ObjC",
                "-framework",
                "KeePassKit",
                "-F$frameworkRootPath/KeePassKit.xcframework/$armSimArch",
                "-framework",
                "KissXML",
                "-F$frameworkRootPath/KissXML.xcframework/$armSimArch",
            )
        }
    }
👀 1
the understanding of
compilerOpts
is crucial
But as you're not using xcframework the format is different.
That's why CocoaPods is easier for integrate different kind of iOS library.
j
How can you see that we are not using xcframework? What are we using then? 🙂
f
Copy code
An XCFramework bundle, or artifact, is a binary package created by Xcode that includes the frameworks and libraries necessary to build for multiple platforms (iOS, macOS, visionOS, tvOS, watchOS, and DriverKit), including Simulator builds. The frameworks can be static or dynamic and also include headers.

Include an XCFramework bundle inside a Swift package to distribute code in binary form for use in other projects. For more information, see Distributing binary frameworks as Swift packages.

<https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle>
Basically, a xcframework is a folder containing subfolder for each targeting Apple platform
It's a standard on iOS...
For what you show, you're using the old format.
j
Is it hard to upgrade to the new format?
Where should the dynamic libraries be placed to be included in the Android and JVM targets?
f
Did you already link/compile them to your library?
j
Checking...
f
if the subject of your issue is just about placing, it will depend on your project configuration, it could be complex.