https://kotlinlang.org logo
Title
k

Kolby Kunz

04/24/2023, 6:49 PM
Hello, I am working on a project that is using a prebuilt static .so file and generated .h with cinterop in kotlin-native. Currently the project will build and compile just fine when none of the methods from the .so file are reference. Once I reference the functions from the .so and attempt to compile my code I am getting a linking error on both linux and macos. The error occurs in the linkDebugExecutableNative step and the error reads out
Undefined symbols for architecture x86_64 '_askar_version', referenced from _askar_askar_version_wrapper76 in result.o ld symbol(s) not found for archutecture x86_64
From what I understand the linker cannot find the definitions for the package for the target platform and is most likely looking in the standard include folders throughout the system but because it is a custom package they are not located there. Any advice on how to fix this would be greatly appreciated or if this is even something supported by cinterop.
v

vbsteven

04/24/2023, 7:10 PM
Did you add the path where the .so file lives to the
linkerOpts
in your .def file?
k

Kolby Kunz

04/24/2023, 7:11 PM
No, that would be something good to do. Can you point me to an example of what that should look like?
v

vbsteven

04/24/2023, 7:11 PM
linkerOpts.linux = \
    -L/usr/local/lib \
    -lgobject-2.0 \
    -lglib-2.0
-L
adds it to the search path (not 100% sure on the terminology),
-l
tells the linker to link against the library with the given name
in this case it means, look for libraries in
/usr/local/lib
and link against
gobject-2.0
and
glib-2.0
k

Kolby Kunz

04/24/2023, 7:13 PM
Since it is static would it be fine to link to a location within the project?
v

vbsteven

04/24/2023, 7:13 PM
There is also an additional flag you can pass to the linkeropts to put it in verbose mode, and then it outputs which locations it is looking in and what libraries it is looking for
Sure, that shouldn't be a problem
k

Kolby Kunz

04/24/2023, 7:14 PM
Thank you I will look into to this
Seems to be finding the directory correctly but the linker is now saying
library not found for -llibaries_askar
the .so is spelled incorrectly so it made sure to match the file name exactly. Not sure what to test next.
v

vbsteven

04/24/2023, 8:16 PM
Can you show the full def file?
k

Kolby Kunz

04/24/2023, 8:17 PM
package = askar
headers = ariesAskar.h
headerFilter = ariesAskar.h

staticLibraries =  libaries_askar.so


linkerOpts.macos_x64 = -Laskar/x86_64/ -llibaries_askar

libraryPaths = askar/x86_64
v

vbsteven

04/24/2023, 8:25 PM
it's a bit weird that you have staticLibraries and then point to an
.so
file which is a shared library
k

Kolby Kunz

04/24/2023, 8:28 PM
Good to know. Was not positive on the definition for this library. Looking into where I was provided the library from it comes from a Rust library and is being used into other projects as c-callable from the given .h file.
After looking into the linker itself the
-l
flag looks fora file with lib appended to the front of it. Knowing that the linking option should now be
aries_askar
causes the compilation to succed