How do I link to native binaries when cross-compil...
# multiplatform
m
How do I link to native binaries when cross-compiling for arm64? I get this error:
Copy code
The /home/mart/.konan/dependencies/aarch64-unknown-linux-gnu-gcc-8.3.0-glibc-2.25-kernel-4.9-2/aarch64-unknown-linux-gnu/bin/ld.gold command returned non-zero exit code: 1.
output:
/home/mart/.konan/dependencies/aarch64-unknown-linux-gnu-gcc-8.3.0-glibc-2.25-kernel-4.9-2/aarch64-unknown-linux-gnu/bin/ld.gold: warning: skipping incompatible /usr/lib//libevdev.so while searching for evdev
/home/mart/.konan/dependencies/aarch64-unknown-linux-gnu-gcc-8.3.0-glibc-2.25-kernel-4.9-2/aarch64-unknown-linux-gnu/bin/ld.gold: error: cannot find -levdev
j
I check them in
m
But then how do I add it to the build script? If I try to add it to linkerOpts I get
Copy code
warning: -linker-option(s)/-linkerOpts option is not supported by cinterop. Please add linker options to .def file or binary compilation instead.
m
oh I get this error for the cinterops linkerOpts, not for the main binary linkerOpts
j
Ah, yeah. I try to keep my def file as empty as possible and use the build DSL for everything
m
Here's my gradle code:
Copy code
kotlin {
    jvm()

    val natives = listOf(
        linuxX64(),
        linuxArm64(),
        mingwX64(),
    )

    natives.onEach {
        it.binaries.sharedLib {
            baseName = "skript-device"
        }

        val main by it.compilations.named("main")

        main.cinterops.create("jni") {
            val javaHome = File(System.getProperty("java.home")!!)
            defFile(projectDir.resolve("src/nativeMain/cinterops/jni.def"))
            includeDirs(
                javaHome.resolve("include"),
                javaHome.resolve("include/linux"),
                javaHome.resolve("include/darwin"),
                javaHome.resolve("include/win32"),
            )
        }

        when (it.name) {
            "linuxX64", "linuxArm64" -> {
                val evdevDir = layout.buildDirectory.dir("libevdev/${it.name}")

                val evdevTask = tasks.register("${it.name}DownloadEvdev", DownloadTarTask::class) {
                    url = when (it.name) {
                        "linuxX64" -> "<https://archive.archlinux.org/packages/l/libevdev/libevdev-1.13.3-1-x86_64.pkg.tar.zst>"
                        "linuxArm64" -> "<https://alaa.ad24.cz/packages/l/libevdev/libevdev-1.13.3-1-aarch64.pkg.tar.xz>"
                        else -> throw IllegalArgumentException()
                    }
                    directory = evdevDir
                }

                main.cinterops.create("evdev") {
                    defFile(projectDir.resolve("src/linuxMain/cinterops/evdev.def"))
                    includeDirs(evdevDir.map { d -> d.dir("usr/include/libevdev-1.0") })

                    afterEvaluate {
                        extraOpts("-libraryPath", "${evdevDir.get()}/usr/lib")
                    }

                    tasks.named(interopProcessingTaskName) {
                        dependsOn(evdevTask)
                    }
                }
            }
            "mingwX64" -> {
                // TODO
            }
        }
    }
}
with the relevant .def file:
Copy code
headers = libevdev/libevdev.h libevdev/libevdev-uinput.h
package = evdev

linkerOpts.linux = -levdev