Hello! I have the following link error. I’m trying...
# kotlin-native
y
Hello! I have the following link error. I’m trying to link a static library that was created with the rust toolchain. I’m getting this error:
Copy code
> Task :examples:sqlite:linkDebugExecutableLinuxArm64 FAILED
e: /Users/xxx/.konan/dependencies/llvm-16.0.0-aarch64-macos-essentials-63/bin/ld.lld invocation reported errors

The /Users/xxx/.konan/dependencies/llvm-16.0.0-aarch64-macos-essentials-63/bin/ld.lld command returned non-zero exit code: 1.
output:
ld.lld: error: undefined symbol: fcntl64
>>> referenced by sqlite3.c
>>>               0343851c9008f270-sqlite3.o:(aSyscall) in archive /Users/xxx/dev/projects/test/sqlx4k/sqlx4k-sqlite/build/classes/kotlin/linuxArm64/main/cinterop/sqlx4k-sqlite-cinterop-ffi/default/targets/linux_arm64/included/libsqlx4k_sqlite.a
I’m building on macOs and I’m getting this error only for
linuxArm64
and
linuxX64
targets. If I explore the symbols of the
.a
file I can successfully find the missing symbol:
Copy code
U fcntl
U fcntl64
Any ideas?
e
U means the symbol is undefined in your .a library - it is expecting to it to be provided from another library that it's linking with
probably the glibc version in the linux sysroot that kotlin-native uses is too old for the rust library you're trying to use
y
Thanks for you reply
Is there a way to provide it?
e
you can try to recompile your rust library inside an older sysroot - Kotlin currently uses GCC 8.3.0, glibc 2.19, Linux 4.9, you need something at least that old
or, you can try
Copy code
freeCompilerArgs += listOf("-linker-option", "--allow-shlib-undefined")
which tells the linker to ignore undefined symbols (hoping that they end up being provided by the actual libc of the system when executed)
y
I just figured it out. I changed the build of the rust project to use
musl
, this resolved the problem.
But thanks for your help 😄
d
musl
meaning what?
e
different libc
generally incompatible with the glibc-based toolchain that most Linux distros use, and that K/N targets, but if it works for you, great