I'm having trouble getting a native program to lin...
# kotlin-native
a
I'm having trouble getting a native program to link on certain distros. On my host machine, I'm running Manjaro, which keeps system libs in
/usr/lib
and
/usr/include
. My program is able to build just fine on this distro. I'm trying to build on Ubuntu, which uses
{/usr/lib,/usr/include}/x86_64-linux-gnu
. I have my compiler options defined in a .def:
Copy code
compilerOpts.linux = -I/usr/include -I/usr/include/x86_64-linux-gnu
linkerOpts.linux = -L /usr/lib -L/usr/lib/x86_64-linux-gnu -lpthread -lssl -lcrypto
My executable is defined in
build.gradle.kts
as follows:
Copy code
binaries {
            executable {
                // Use system C libraries
                val sysRoot = "/"
                val libgccRoot = File("/lib/gcc/x86_64-linux-gnu/").takeIf { it.exists() }
                    ?: File("/lib/gcc/x86_64-pc-linux-gnu/")
                // Use the most recent GCC available on the host
                val libgccPath = file("${libgccRoot.absolutePath}/${libgccRoot.list()!!.last()}")
                val overriddenProperties =
                    "targetSysRoot.linux_x64=$sysRoot;libGcc.linux_x64=$libgccPath"
                val compilerArgs = "-Xoverride-konan-properties=$overriddenProperties"
                this.freeCompilerArgs += listOf(compilerArgs)
                this.entryPoint = "opstopus.deploptopus.main"
                this@binaries.findTest("debug")?.let { it.freeCompilerArgs += listOf(compilerArgs) }
            }
        }
On Ubuntu, I consistently get this error:
Copy code
/root/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold: error: cannot open //usr/lib/crt1.o: No such file or directory
/root/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold: error: cannot open //usr/lib/crti.o: No such file or directory
/root/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold: error: cannot open //usr/lib/crtn.o: No such file or directory
I confirmed that all 3 of these object files are in
/usr/lib/x86_64-linux-gnu
on Ubuntu. Why is it only searching in
/usr/lib
?
If you're wondering why I'm using system libraries, it's because the current version of OpenSSL on Manjaro stable is incompatible with Kotlin Native's bundled glibc