Skip to content

undefined reference with ndk r12  #126

Closed

Description

@1bsyl

I have updated from NDK r11c to r12 and there are some missing references when loading my shared library:
(at least):
00000000 DF UND 00000000 LIBC_N __aeabi_memclr4
00000000 DF UND 00000000 LIBC_N __aeabi_memmove
00000000 DF UND 00000000 LIBC_N __aeabi_memclr8
00000000 DF UND 00000000 LIBC_N __aeabi_memcpy
00000000 DF UND 00000000 LIBC_N __aeabi_memcpy4
00000000 DF UND 00000000 LIBC_N __aeabi_memclr
00000000 DF UND 00000000 LIBC_N __aeabi_memset
00000000 DF UND 00000000 LIBC_N __aeabi_atexit

Activity

  1. dimitry- commented on Jun 19, 2016

    @dimitry-
    Contributor

    Looks like you are targeting 24 but running on previous version of android.

  2. 1bsyl commented on Jun 19, 2016

    @1bsyl
    Author

    Yes, I was about to write the solution, I am using targetSdkVersion=24 on a lower device.

  3. 1bsyl commented on Jun 19, 2016

    @1bsyl
    Author

    I reopen to have more feedback:

    With (compileSdkVersion=24, targetSdkVersion=23), it runs.
    But it requires to install both SDK Platform 23 & 24. Why, since I specified "compileSdkVersion=24", I would expect to download and need only the package "Android N (API 24) SDK Plaform" ?

    According to:
    http://stackoverflow.com/questions/26694108/what-is-the-difference-between-compilesdkversion-and-targetsdkversion

    I should be able to bump "targetSdkVersion" to 24, but it fails to run because of undefined reference (at least "__aeabi_memclr4"). Doesn't seem to be an API thing, but more low level library issue ?

    Signification of {min,max,target, compile}SdkVersion is quite blur ... (for years)

  4. reopened this on Jun 19, 2016
  5. DoDoENT commented on Jun 29, 2016

    @DoDoENT

    Also happens to us, but only for armeabi-v7a target on some devices (HTC One M8, Android 6.0; SGS5; Android 6.0). It is weird that it does not happen on SGS4, Android 5.0.1 nor on Huawei P8Lite, Android 5.0.1. It also does not happen on arm64-v8a on SGS6, Android 6.0.

  6. DoDoENT commented on Jun 29, 2016

    @DoDoENT

    Confirmed that setting target=android-23 works. Are there any known workarounds to make it work when targeting android-24? We had similar issue when upgrading from android-19 to android-21 in order to be able to use GLES3 on compatible devices - some functions used to be defined in headers in android-19 platform and were moved to lib in android-21 - therefore we needed to implement those functions in our code.

  7. DoDoENT commented on Jun 29, 2016

    @DoDoENT

    Where are these functions defined?

    $ grep -rIn __aeabi_memclr4 .
    

    finds nothing.

  8. dimitry- commented on Jun 29, 2016

    @dimitry-
    Contributor

    I think there is confusion between targetSdkVersion and LOCAL_SDK_VERSION

    NDK interpretation of LOCAL_SDK_VERSION is minimum SDK version - which means that it is not guaranteed to work on devices with sdk < LOCAL_SDK_VERSION.

    I am not sure how targetSdkVersion gets propagated to LOCAL_SDK_VERSION - do you use gradle to build native libraries?

    (You are getting this error because if LOCAL_SDK_VERSION is set to 24 these symbols get LIBC_N version. These symbols were mistakenly versioned as LIBC_PRIVATE instead of LIBC in android-23 which was fixed in 24, hence the symbol version mismatch if you try to run load the library linked against libc.so from android-24 on android-23)

  9. 1bsyl commented on Jun 29, 2016

    @1bsyl
    Author

    @DoDoENT
    I believe this is used implicitly, when application uses "memset", or maybe when initializing some array. You linked (statically) with the libc of the targeted sdk.

    Then, calling objdump -T on my shared library displays:

    targetSdkVersion 24:
    00000000 DF *UND* 00000000 LIBC_N __aeabi_memclr4

    targetSdkVersion 23:
    00000000 DF *UND* 00000000 __aeabi_memclr4

    I use gradle, but with some ndk commands so that it seems equivalent to calling ndk-build
    (with command line option APP_PLATFORM=android-24)

    My build.gradle contains
    targetSdkVersion 23 (or 24, which leads to the issue)
    compileSdkVersion 24

    AndroidManifest.xml, my minSdkVersion is 10.

    According to : https://developer.android.com/guide/topics/manifest/uses-sdk-element.htm

    android:targetSdkVersion

    An integer designating the API Level that the application targets. If not set, the default value equals that given to minSdkVersion.

    This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).

  10. DoDoENT commented on Jun 29, 2016

    @DoDoENT

    @1bsyl, I was referring to APP_PLATFORM NDK parameter - it has to be set to android-23 or lower. Nevertheless, in your build.gradle you can target API level 24 (it is used only for Java code).

  11. 1bsyl commented on Jun 29, 2016

    @1bsyl
    Author

    In fact, the safest, is to set APP_PLATFORM to the minSdkLevel ?
    And to keep other "targetSdkVersion" and "compileSdkVersion" to 24.

  12. DoDoENT commented on Jun 29, 2016

    @DoDoENT

    @1bsyl indeed, unless you need to use some NDK features available only in later API levels (like for example GLES3 on compatible devices, while falling back to GLES2 on older devices - in order to access GLES3 headers, you need APP_PLATFORM=android-21 or later, which produces binary which is not so compatible with KitKat and earlier Android versions).

  13. 1bsyl commented on Jun 29, 2016

    @1bsyl
    Author

    @DoDoENT
    Ok! your example totally makes sense.

    And, bumping targetSdkVersion to 24 in build.gradle and AndroidManifest.xml, can it have some bad side effect ? (while keeping a lower APP_PLATFORM for the ndk side).

  14. DoDoENT commented on Jun 29, 2016

    @DoDoENT

    @1bsyl from our experience at MicroBlink we recommend having compileSdkVersion always set to latest stable API level (currently this is 24), targetSdkVersion set to latest API level with which you have extensively tested your app (for us this is still 23, as we cannot test with 24 because Android N is still not released - bugs and failures on preview versions can be attributed to both bugs in your app as well as bugs in platform itself - this is why we usually wait for Google to release official build of new Android version and then we test on it) and minSdkVersion set to minimum API level your app supports (for us this is still 10 :-( ).

    One example where you may put your targetSdkVersion to 21, while using compileSdkVersion on 24 would be case when you have not implemented Android M permission model in your app. Similarly, if you have not prepared your app to work in multi-window environment introduced in Android N (will it be called Nutella?) you should not set targetSdkVersion to 24 (setting it so would mean that you have tested your app in multi window environment and this feature will be enabled for your app on devices running Android N).

    On NDK side, you should set APP_PLATFORM to same as minSdkVersion in build.grade to be absolutely sure your app will work correctly. However, if you need NDK features that were introduced in later API levels, you should set APP_PLATFORM to minimum API level which gives a feature you need and then test intensively on lower API levels to ensure everything works (this may require some weird hacks to ensure binary built with APP_PLATFORM=android-23 to work on Gingerbread :-P ).

  15. 23 remaining items

  16. ajunkala commented on Oct 6, 2017

    @ajunkala

    Found the solution. You can set the NDK target version with

    android.ndk {
    platformVersion = "19"
    }

  17. DanAlbert commented on Oct 6, 2017

    @DanAlbert
    Contributor

    Is platformVersion the thing it uses? I'm not a gradle user so I don't know how to configure it, but whatever gradle is using for your NDK API level needs to match your minSdkVersion.

  18. ajunkala commented on Oct 6, 2017

    @ajunkala

    That seems to be the case. Like I noted, I can repro the issue even w/ an emulator. I just added it and the issue seems to be resolved now.

  19. Rajveer86 commented on Mar 23, 2018

    @Rajveer86

    @DanAlbert Sorry to bring up an old issue, however I am experiencing exactly what you described here (relating to this).

    I have an OpenGL ES 3.0 project which supports devices on KitKat (API 19) and have the following configuration:

    compileSdkVersion = 26
    minSdkVersion 19
    targetSdkVersion 26
    
    cmake {
        arguments '-DANDROID_PLATFORM=android-19', '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static'
    }
    

    with #include <GLES3/gl3.h> used for including the OpenGL ES header.

    I now want to use some 3.1 and 3.2 functions on devices that support them so have modified ANDROID_PLATFORM to DANDROID_PLATFORM=android-24 and my header include to #include <GLES3/gl32.h>. This (correctly) leads to my Android 5.0 (API 21) test device failing to load my native library with the error:

    dlopen failed: cannot locate symbol [insert new 3.1/3.2 function name here]

    I have no problem with finding whether these newer functions exist at runtime using eglGetProcAddress, however after reading your comment on unified headers (specifically the second paragraph about it being made easier) is this still the recommended way or is there an easier one?

  20. enh commented on Mar 23, 2018

    @enh
    Contributor

    eglGetProcAddress is still the recommended way. danalbert was just saying that unified headers mean that you'll have the <GLES3/gl3.h> header available even if you're targeting an API level that predates that header.

  21. Rajveer86 commented on Mar 23, 2018

    @Rajveer86

    I see, that makes perfect sense. Thank you for the quick reply, I'll go ahead with that route then :)

  22. neevek commented on May 20, 2019

    @neevek

    Sorry to bring this up again, but how do I resolve the issue if I have to target 28 and support devices starting from 21? I am using NDK r19c.

    dlopen failed: cannot locate symbol "__aeabi_memclr8" 
    
  23. DanAlbert commented on May 20, 2019

    @DanAlbert
    Contributor

    Stop doing that. Your NDK API level is your minSdkVersion.

  24. neevek commented on May 20, 2019

    @neevek

    If I set the NDK API level to 21, it failed with 718

    undefined reference to 'globfree'
    

    which was fixed in r17b. Now this is a dead end to me.

  25. enh commented on May 20, 2019

    @enh
    Contributor

    If I set the NDK API level to 21, it failed with 718

    undefined reference to 'globfree'
    

    which was fixed in r17b. Now this is a dead end to me.

    it's a mistake to think that globfree() was "fixed" in r17b. glob() and globfree() were added in API 28. you cannot use them in an app that needs to run on earlier OS versions.

    (a workaround is to copy the source from bionic in AOSP into your app's source.)

  26. Yaakushi commented on Feb 11, 2020

    @Yaakushi

    I know this is an old and closed issue for an older version of the NDK, and I apologize for posting here, but I'm going through the exact same issue (java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__aeabi_memclr8" referenced by "libtwampc.so"... on devices running androud 4.x), and I'm fairly confident that I got the right API level (but I could be wrong).

    I'm compiling using a standalone toolchain, and my environment setup currently looks like this:

    export ARCHITECTURE=armv7a-linux-androideabi
    export API_LEVEL=16
    
    export NDK_VERSION=20.1.5948944
    export NDK=$HOME/Android/Sdk/ndk/$NDK_VERSION/
    export HOST_TAG=linux-x86_64
    
    export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_TAG
    export AR=$TOOLCHAIN/bin/${ARCHITECTURE}-ar
    export AS=$TOOLCHAIN/bin/${ARCHITECTURE}-as
    export CC=$TOOLCHAIN/bin/${ARCHITECTURE}${API_LEVEL}-clang
    export CXX=$TOOLCHAIN/bin/${ARCHITECTURE}${API_LEVEL}-clang++
    export LD=$TOOLCHAIN/bin/${ARCHITECTURE}-ld
    export RANLIB=$TOOLCHAIN/bin/${ARCHITECTURE}-ranlib
    export STRIP=$TOOLCHAIN/bin/${ARCHITECTURE}-strip

    And my CPPFLAGS looks like this:

    export CPPFLAGS='-g -fPIC -DANDROID_PLATFORM=android-16 -DAPP_PLATFORM=android-16 -D__ANDROID_API__=16'

    (I've added the defines for ANDROID_PLATFORM, __ANDROID_API__, and APP_PLATFORM after going through a few similar issues, but they did absolutely nothing for me)

    As far as I understand, I'm compiling my binary for anything at API level 16 or above, and yet, it consistently crashes with devices running android 4.x (e.g. 4.3, 4.4.2, all running under armeabi-v7a). Am I overlooking something? Am I doing something stupid? Or is this really an issue?

  27. DanAlbert commented on Feb 11, 2020

    @DanAlbert
    Contributor

    Are those flags what you're using to build libtwampc.so? Or is that a prebuilt and it's just a dependency of what you're building?

  28. Yaakushi commented on Feb 12, 2020

    @Yaakushi

    Sorry for forgetting such a crucial detail. Those are the flags I'm using to build libtwampc.so and another library used by libtwampc as a dependency. I can load the dependency library just fine, even in the devices where trying to load libtwampc.so fails.

  29. DanAlbert commented on Feb 12, 2020

    @DanAlbert
    Contributor

    Could you file a new bug with the readelf -sW $LIBRARY | grep __aeabi_memclr8 output for each of your libraries?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions