Android NDK: no archive symbol table (run ranlib)

Viewed 3290

I am updating my projects to use Android ndk 16b and it was previously using 12b (was working fine). After I updated, I am running into the following error while building the final .so:

/Users/ssk/code/client/git/thirdparty/android-ndk-r16b/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: jni/../../../shared-library/SharedCommon/build/arm-linux-androideabi/lib/libSharedCommon.a: no archive symbol table (run ranlib)

This is leading to a bunch of linker errors. I tried the following answers:

Android NDK: no archive symbol table

How to run ranlib on an archive built through Android.mk?

no archive symbol table (run ranlib) while building libcryptopp.a through ndk-build

with no luck.

3 Answers

You need to build static libraries with a GNU AR (like the one we include in the NDK, same directory as GCC). Darwin's AR is a BSD AR that does not automatically perform ranlib tasks.

When cross compiling a library for android, I encounter similar issue.

The problem arouse because I didn't specify ranlib tool for cross compiling, and it fallback to use a default one in the build system which is x86.

The issue solved by specifying the ranlib to arm-linux-androideabi-ranlib in configuration stage before compiling.

For one of my library adding

NDK=$HOME/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin/
cmake -DCMAKE_RANLIB=$NDK/x86_64-linux-android-ranlib ...

fixed the issue. For another one library it didn't work and needed adding also

-DCMAKE_C_COMPILER_RANLIB=$NDK/x86_64-linux-android-ranlib -DCMAKE_CXX_COMPILER_RANLIB=$NDK/x86_64-linux-android-ranlib ...

Also you may need add reference to ar ndk tool

-DCMAKE_AR=$NDK/x86_64-linux-android-ar

Adding C or CXX depends on what you using gcc/clang or gcc++/clang++. To set right compiler use flags like DCMAKE_C_COMPILER or DCMAKE_CXX_COMPILER for cmake.

Related