libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.92k stars 1.84k forks source link

undefined symbol with cmake vs ndk-build #10172

Closed Duron27 closed 4 months ago

Duron27 commented 4 months ago

building for android with cmake vs ndk-build gives ld.lld: error: undefined symbol: SDL_SendMouseButton ld.lld: error: undefined symbol: Android_Window when I compile my app also the libSDL2.so file is about 200 kbs smaller which is strange

Duron27 commented 4 months ago

I had to drop to version 2.24.0 for a project, is there a flag or workaround for this? for context this is how I'm using it https://gitlab.com/cavebros/openmw-android-docker/-/blob/Testing/Dockerfile#L255 and here is the ndk-build version that works https://gitlab.com/cavebros/openmw-android-docker/-/blob/main/Dockerfile?ref_type=heads#L255

and here is the file that gives the lld errors https://gitlab.com/cavebros/openmw-android-docker/-/blob/main/patches/openmw/android_main.cpp?ref_type=heads

madebr commented 4 months ago

Android_Window is an internal SDL_Window, which is not supposed to be visible outside of the SDL2 library.

https://github.com/libsdl-org/SDL/blob/6a1030956897de3c9550d98704a449f25563a3cf/src/video/android/SDL_androidwindow.c#L37

I cannot build any example using Android_Window when linked to a shared SDL2/3 library, but when I disable this "shield" (-DHAVE_GCC_FVISIBILITY=OFF), the internal symbols become visible again.

The better solution is of course to not let your design depend on SDL internals.

Duron27 commented 4 months ago

yea building with -latomic -no-canonical-prefixes -Wl,--gc-sections -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--no-undefined -Wl,--fatal-warnings -Wl,--no-undefined-version -ldl -lGLESv1_CM -lGLESv2 -lOpenSLES -llog -landroid -ldl -lc -lm` solved it for me

Duron27 commented 4 months ago

I wish I could but I don't have the skill to update the code atm

extern SDL_Window Android_Window; extern "C" int SDL_SendMouseMotion(SDL_Window window, int mouseID, int relative, int x, int y); extern "C" void Java_org_libsdl_app_SDLActivity_sendRelativeMouseMotion(JNIEnv *env, jclass cls, int x, int y) { SDL_SendMouseMotion(Android_Window, 0, 1, x, y);

from https://github.com/Duron27/openmw-android/blob/f03f13dc152e563355df998a931da072ddc9d496/buildscripts/patches/openmw/android_main.cpp#L44C1-L47C53

madebr commented 4 months ago

Upstream OpenMW also uses SDL internals. https://gitlab.com/OpenMW/openmw/-/blob/master/apps/openmw/android_main.cpp?ref_type=heads#L41

I suggest raising an issue there to re-implement this using the public SDL api.