jozols
jozols

Reputation: 592

Linking static libraries libm.a or libc.a with NDK cmake

Is it possible to link platforms\android-XX\arch-arm\usr\lib*.a versions of libraries when using NDK Cmake build system with Android Studio? I'm using LLVM toolchain and Android NDK 13.

I have tried modifications on sample app, changing file: https://github.com/googlesamples/android-ndk/blob/master-cmake/hello-jni/app/src/main/cpp/CMakeLists.txt

With following modification (adding libm.a):

target_link_libraries(hello-jni libm.a android log)

Builds successfully, but readelf -d reveals that libm.so is still linked:

 0x00000001 (NEEDED)                     Shared library: [libandroid.so]
 0x00000001 (NEEDED)                     Shared library: [liblog.so]
 0x00000001 (NEEDED)                     Shared library: [libm.so]
 0x00000001 (NEEDED)                     Shared library: [libdl.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]

When adding also libc.a it gets worse, building fails:

Error:error: relocation overflow in R_ARM_THM_JUMP11
Error:error: linker command failed with exit code 1 (use -v to see invocation)

BTW, sometimes I see only last error without any explanation (for example, when misspelling library name). Should I set -v flag somehwere to see more details? How to do it?

Upvotes: 1

Views: 3859

Answers (1)

Surge1223
Surge1223

Reputation: 101

If you're just wanting to get this to compile, I'd try to use arm-linux-androideabi-gcc instead of clang. I realize that gcc is depreciated. But I can't if your goal is to compile or understand the problem. Judging from Dan's comment, I'm assuming that he doesn't believe any of the the flags he commented on in aosp will help (see link below)

https://android.googlesource.com/platform/build/+/master/core/clang/config.mk

FWIW, I tend to always use static libs from aosp/bionic builds I do because I work on numerous things that require them. there tends to be too much inconsistency in symbols included in bionics libc between sdk versions, that and for statically linking its required to use libc.a for the most part I believe. If you're going to use a ndk version of a static libc, I would suggest using platform 21 instead of 24.

I figure that since Android is so fragmented, and all devices use different libc.so, libdl.so, etc that it can't cause too many issues.

EDIT: misread the question.

Upvotes: 1

Related Questions