-1

I'm trying to implement an OEX (open engine exchange protocol) chess program for Android. This has been discussed at What is OEX (Open Exchange Protocol?) and can I call such APK from my app? earlier.

The java-part of the program runs fine, yet the native library always segfaults. Even with something simple as

#include <stdio.h>

int main(int argc, char *argv[])
{
        printf("Hello, world!\n");

        return 0;
}

I noticed one thing to be different: the libstockfish.so library seems to be linked to /system/bin/linker while my library is not linked at all?

file libs/x86_64/libstockfish.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, BuildID[sha1]=b690a6bb7630099c6618950a9e1604850f1de836, stripped

file libs/x86_64/libDog.so libs/x86_64/libDog.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=93a9d3635eef9fc0f2140a87956db9ac80459993, stripped

What is it that I could be doing wrong?

I'm using the ndk-build script:

jni/Application.mk:

APP_ABI := all
APP_PLATFORM     := 21
#NDK_TOOLCHAIN_VERSION := 4.9
APP_STL := c++_shared
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -std=c++17

jni/Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := Dog
LOCAL_SRC_FILES := test.cpp

LOCAL_STRIP_MODE := none

LOCAL_PRELINK_MODULE := false

LOCAL_CPPFLAGS += -std=c++17 -Wall -DVERSION=\"0.8\" -DNAME_EXTRA=\"\" -fexceptions -Wno-c++11-narrowing -fPIC -pie -fPIE
LOCAL_LDLIBS += -shared
LOCAL_LDFLAGS += -fPIC -pie -fPIE -Wl,--entry=main,-dynamic-linker=/system/bin/linker

LOCAL_CPP_FEATURES := exceptions

include $(BUILD_SHARED_LIBRARY)

Any ideas?

Folkert van Heusden
  • 433
  • 4
  • 17
  • 38
  • [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) - bugs that cause a segfault or other reproducible crashes are among the easiest to solve with a debugger. – Jesper Juhl Oct 20 '22 at 19:21
  • It crashes before main is invoked. Also running that Hello World as an executable runs fine. – Folkert van Heusden Oct 20 '22 at 19:30
  • One can debug before `main`. – Jesper Juhl Oct 20 '22 at 19:43
  • Are you running on a custom ROM or rooted Android device? The Android NDK is for building dynamic libraries which are then called from Java/Kotlin and don't use `main` as an entry point. Also the C runtime support library has been modified to remove support for unnecessary facilities. – Richard Critten Oct 20 '22 at 19:59
  • No i am using the emulator from the sdk. Regarding the entry point: i believe oex specifies main, not a different symbol.. – Folkert van Heusden Oct 20 '22 at 20:05

1 Answers1

0

Found the solution: apparently the idea is to trick the packaging system by creating a regular binary and renaming it to e.g. libstockfish.so. Then the board-programs can happily import them and play chess with them.

Folkert van Heusden
  • 433
  • 4
  • 17
  • 38