Kotlin Multiplatform library from Raspberry Pi

I’m developing my first Multiplatform library.

In my first tests with a method that returns “Hello World” I have managed to use the library from C # (. NET), C++ (windows and debian 64bit) but I am having problems getting it to work correctly on a Raspberry (Raspbian 32bit).

From a Raspberry, if I compile the project as executable it works fine and shows “Hello world” in the console. However, if I compile it as a dynamic library it doesn’t work properly

This is the sample code:

fun hello(): String = "Hello World"

fun main()

This is what I have in the build.gradle file:

kotlin {
        binaries {
            sharedLib {
            executable {
                entryPoint "main"

The compilation works correctly and it generates a .so file and a .h file that I copy to the Raspberry.

This is the testing program:

#include <dlfcn.h>
#include <iostream>
#include "libTestKotlin_api.h"

int main(int argc, char **argv)
    void *handle;
    char *error;
    handle = dlopen ("/home/pi/libTestKotlin.so", RTLD_LAZY);
    if (!handle) {
        fputs (dlerror(), stderr);
    return 0;

To compile this program I use this command:

g++ -o test test.cpp -ldl

The compilation works correctly but when executing the program in the call to “dlopen” it returns the following error:

cannot open shared object file: No such file or directory

To make sure the call to dlopen is correct, I have tried to copy an existing library such as “libpiogpio.so” in the same directory and with the same name and then “dlopen” works correctly.

¿What could be wrong?

This is the generated library information:

file libTestKotlin.so
libTestKotlin.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, BuildID[xxHash]=62dc0b62f2061df0, not stripped

readelf -h libTestKotlin.so
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2’s complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: ARM
Version: 0x1
Entry point address: 0x11000
Start of program headers: 52 (bytes into file)
Start of section headers: 459324 (bytes into file)
Flags: 0x5000400, Version5 EABI, hard-float ABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 12
Size of section headers: 40 (bytes)
Number of section headers: 35
Section header string table index: 33

readelf -d libTestKotlin.so | grep ‘NEEDED’
0x00000001 (NEEDED) Shared library: [libdl.so.2]
0x00000001 (NEEDED) Shared library: [libm.so.6]
0x00000001 (NEEDED) Shared library: [libpthread.so.0]
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x00000001 (NEEDED) Shared library: [ld-linux-armhf.so.3]
(this shared libraries are the same as in the executable that does work.)

ldd libTestKotlin.so
not a dynamic executable

I have tried a lot of things but I can’t get it to work on the Raspberry. I would appreciate your help. Thank you very much in advance.