Consider the following example:
- Project
foois a KMP library with cinterop dependencies. The dependencies are built with system toolchain and target system libraries, e.g. glibc > 2.20 - Project
baris a KMP / KN executable with a dependency onfoo. Whenkonanis invoked to build and linkbar, it uses its own bundled LLVM and sysroot - The sysroot bundled with
konan(available in~/.konan/dependencies) is heavily outdated (kernel 4.9.2, glibc 2.19) even though the LLVM toolchain is relatively recent (LLVM-19 essentials as of October 2025).
When I build this project targeting any other platform (iOS, macOS, Android – although it uses nativeExternalBuild instead of cinterop) the resulting binary links and runs fine. But when building for Linux it fails with linker errors and missing symbols from glibc.
Providing accurate real paths with linkerOpts does not appear to change anything (likely since the “sysroot” variants take precedence). After a longer investigation I managed to link with the following configuration:
linkerOpts.addAll(listOf(
"-L/usr/lib/x86_64-linux-gnu",
"-lc++",
"--allow-shlib-undefined",
"--unresolved-symbols=ignore-all",
"--warn-unresolved-symbols",
))
and forcing libc++ in both projects.
This is not a new issue, c.f.:
- https://stackoverflow.com/questions/78244706/how-to-use-a-newer-linker-and-glibc-in-a-kotlin-native-project
- How to use default system clang\llvm for kotlin-native?
- kotlin/kotlin-native/HACKING.md at 7a13023b1463b651904440e3ffbedf1bfa379c9b · JetBrains/kotlin · GitHub
In general, what is the recommended way to tackle these kinds of problems? I feel like it took me way too long to solve (or rather sweep under the rug) something that should be relative simple and work out of the box. In the coming days I might try to build the cinterop package with the bundled toolchain (see the last link), but to be frank, glibc 2.19 has been released over 11 years ago and it lacks some pretty important security features.