Miguel Santos
04/08/2024, 9:43 AMcompileNativeMainKotlinMetadata
:
e: file:///Users/myuser/Projects/demo/src/nativeMain/Main.kt:12:8 Unresolved reference: libpq
In summary:
Linux machine (x64):
• linuxX64 ✅
• linuxArm64 ❌ (I think it's supposed to work)
Macos machine (arm64):
• macosX64 ✅
• macosArm64 ✅
• linuxX64 ❌
• linuxArm64 ❌
Not sure why linuxX64 works on Linux machine but not Macos. Appreciate if someone could provide help or even a way to debug this issue (not sure where to start).Miguel Santos
04/08/2024, 9:44 AMmacosArm64 {
val main by compilations.getting
val libpq by main.cinterops.creating {
defFile(project.file("src/nativeInterop/cinterop/libpq.def"))
}
}
Landry Norris
04/08/2024, 12:36 PMMiguel Santos
04/08/2024, 12:41 PMheaders = libpq-fe.h
headerFilter = *
package = libpq
compilerOpts = -I/opt/homebrew/opt/libpq/include -I/usr/local/opt/libpq/include
linkerOpts = -L/opt/homebrew/opt/libpq/lib -L/usr/local/opt/libpq/lib -lpq
Miguel Santos
04/08/2024, 1:23 PMcompileNativeMainKotlinMetadata
for all targets, but I don't fully understand what it does:
kotlin.mpp.enableCInteropCommonization=true
However, it now fails for linkDebugTestLinuxX64
:
ld.lld: error: undefined symbol: PQsetdbLogin
>>> referenced by out
>>> /private/var/folders/dg/z7k2610n0vd0qgqzc7v17pxr0000gn/T/konan_temp16050745230498861662/test.kexe.o:(libpq_PQsetdbLogin_wrapper5)
>>> did you mean: _PQsetdbLogin
>>> defined in: /usr/local/opt/libpq/lib/libpq.a
So: macosArm64 ✅ , macosX64 ✅ , linuxArm64 ✅, linuxX64 ❌.
For reference, I also had to stop using the same libpq.def
for all targets, since macosX64
was failing on linkDebugTestMacosX64
because it was finding the arm64 version of libpq
first:
ld: symbol(s) not found for architecture x86_64
So now arm64 .def points to arm64 libpq installation, and x64 .def points to x64 libpq installation.Miguel Santos
04/08/2024, 3:47 PMlibpq
homebrew version for macosX64 isn't compatible with linuxX64, even though the arm64 ones are. Compiling successfully for all 4 targets now.
Problem is, having a different .def
file (i.e., link paths) for each target isn't suitable for this project, because it is a library.
So I still have to find a way to have the same .def
for all targets, and be able to build this in my machine and in a pipeline.Landry Norris
04/08/2024, 3:49 PMlinkerOpts.linuxX64 = ...
linkerOpts.macosArm64 = ...
...
Landry Norris
04/08/2024, 3:50 PMMiguel Santos
04/08/2024, 3:52 PMLandry Norris
04/08/2024, 3:58 PMMiguel Santos
04/08/2024, 3:59 PM