GNOME Bugzilla – Bug 766235
undefined reference to 'bsd_signal' in Android Studio 2.1
Last modified: 2016-06-07 07:04:55 UTC
Using NDK build on GStreamer version 1.8.1 causes the error below: /home/slomo/cerbero/android-ndk-r11/platforms/android-9/arch-arm/usr/include/signal.h:113: error: undefined reference to 'bsd_signal' I am using Android Studio 2.1 with Android NDK v.12.
Created attachment 327601 [details] Image showing error and NDK version
Created attachment 327603 [details] [review] Patch for reproducing error Patch is based off of project listed here: https://github.com/sdroege/gst-player/tree/master/android
Review of attachment 327603 [details] [review]: ::: android/app/src/main/jni/Application.mk @@ +1,1 @@ +APP_PLATFORM = 21 Ah I assume it works if you select 15 or 9 here, independent of the other changes?
(In reply to Sebastian Dröge (slomo) from comment #3) > Ah I assume it works if you select 15 or 9 here, independent of the other > changes? Neither API 15 or 9 fixes the problem. I get the same error.
Ok, so it fails to build for you even without any changes then? Good :) Not sure what this NDK 12 is, the latest still seems to be r11c: https://developer.android.com/ndk/downloads/index.html
(In reply to Sebastian Dröge (slomo) from comment #5) > Not sure what this NDK 12 is, the latest still seems to be r11c: > https://developer.android.com/ndk/downloads/index.html Hmm, I'm guessing the website has not been updated yet. If you download Android Studio 2.1 from the stable channel, I'm sure you'll be able to download it. Here is a link to the copy of the NDK I am using: https://www.dropbox.com/s/la88jgjzwnj6ilz/ndk-bundle.tar.gz?dl=0
Created attachment 327607 [details] Android NDK v12 download Turns out NDK v12 is a beta build.
I can't reproduce this here with your ndk-bundle. Can you reproduce it with r11c?
Also please try with latest gst-player (I just updated something) without any changes to the build system.
I am still getting the same error: sbis-android@ubuntu:~/Android/Projects/gst-player-new/android/app$ /home/sbis-android/Android/Sdk/android-ndk-r11c/ndk-build NDK_PROJECT_PATH=build APP_BUILD_SCRIPT=src/main/jni/Android.mk NDK_APPLICATION_MK=src/main/jni/Application.mk GSTREAMER_JAVA_SRC_DIR=src/main/java GSTREAMER_ROOT_ANDROID=/home/sbis-android/Android/Installation/gstreamer-1.0-android-armv7-1.8.1 all [armeabi] Compile thumb : gstplayer <= player.c GStreamer : [GEN] => gst-build-armeabi/gstreamer_android.c GStreamer : [COMPILE] => gst-build-armeabi/gstreamer_android.c GStreamer : [LINK] => gst-build-armeabi/libgstreamer_android.so /home/slomo/cerbero/android-ndk-r11/platforms/android-9/arch-arm/usr/include/signal.h:113: error: undefined reference to 'bsd_signal' /home/slomo/cerbero/android-ndk-r11/platforms/android-9/arch-arm/usr/include/signal.h:113: error: undefined reference to 'bsd_signal' /home/slomo/cerbero/android-ndk-r11/platforms/android-9/arch-arm/usr/include/signal.h:113: error: undefined reference to 'bsd_signal' /home/slomo/cerbero/android-ndk-r11/platforms/android-9/arch-arm/usr/include/signal.h:113: error: undefined reference to 'bsd_signal' collect2: error: ld returned 1 exit status /home/sbis-android/Android/Installation/gstreamer-1.0-android-armv7-1.8.1/share/gst-android/ndk-build//gstreamer-1.0.mk:229: recipe for target 'buildsharedlibrary_armeabi' failed make: *** [buildsharedlibrary_armeabi] Error 1
Do you run ndk-build manually there, or just run ./gradlew assemble ?
I run it manually. Here is the full command from the app folder of the gst-player project: /home/sbis-android/Android/Sdk/android-ndk-r11c/ndk-build NDK_PROJECT_PATH=build APP_BUILD_SCRIPT=src/main/jni/Android.mk NDK_APPLICATION_MK=src/main/jni/Application.mk GSTREAMER_JAVA_SRC_DIR=src/main/java GSTREAMER_ROOT_ANDROID=/home/sbis-android/Android/Installation/gstreamer-1.0-android-armv7-1.8.1 all
Is there any other information I can give you? This has become a blocker in my project.
I can finally reproduce it, on my laptop. It works well on my desktop though.
Apparently ABI breakage in the NDK: https://github.com/rust-lang/libc/issues/236#issuecomment-198774409 If we compile with pre-21, our binaries won't work with 21 or newer. If we compile with 21 or newer it won't work with pre-21. Good job Google!
https://github.com/android-ndk/ndk/issues/48
We could maybe detect it at link time or so, and inject a bsd_signal() wrapper if needed. Ugly though. Someone will have to implement that though.
It might be possible to declare bsd_signal() locally as a weak alias for 'signal'. If the NDK one is present, it shouldn't conflict and the NDK version will take precedence. __sighandler_t bsd_signal(int, __sighandler_t) __attribute__((weak, alias ("signal")));
Main question (if that works at all) is where to put that code then :) I assume gstreamer_android-1.0.c.in is a good place. I'll test this later.
commit 056dc09609fae74d94899ed8d5ff71832d73a0a0 Author: Sebastian Dröge <sebastian@centricular.com> Date: Sat May 14 10:35:22 2016 +0300 android: Work around NDK ABI incompatibility Workaround for Android <21 making signal() an inline function around bsd_signal(), and Android >= 21 not having any bsd_signal() symbol but only signal() https://bugzilla.gnome.org/show_bug.cgi?id=766235
See https://bugzilla.gnome.org/show_bug.cgi?id=766998
This seems to sometimes create an infinite recursion, where bsd_signal() calls bsd_signal() calls bsd_signal() calls ...
Created attachment 329192 [details] [review] android: Work around NDK ABI incompatibility around bsd_signal/signal in a different way Get the correct symbol via dlsym() instead of letting the linker figure it out. Letting the linker do it can bring us into infinite recursion calling into our very own weak symbol.
Can you check if this also works well for you, Diane and Gregoire?
I had an undefined symbol of signal from the linker without the aforementioned patch.
On gstreamer very latest 1.9.x (git clone on June 6 morning), I'm seeing the compilation problem again, aka. it doesn't find the signal symbol. In manifest, I have: <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="22" /> In Application.mk, I have: APP_ABI := armeabi-v7a Also, I'm using /opt/google/android/ndk-r10e/ndk-build If I apply the patch marked "2016-06-06 13:48 UTC, Sebastian Dröge (slomo)", the compilation problem disappears.
Attachment 329192 [details] pushed as 577f883 - android: Work around NDK ABI incompatibility around bsd_signal/signal in a different way
Thanks for testing!