0

description

We have a C/C++ project wallet-core that is using third party library libsecp256k1, and we install libsecp256k1 into /usr/local/lib and /usr/local/include, all works well in wallet-core Unit Test, till we add it to android, which call wallet-core.

call links: android project -> wallet-core -> trezor_crypto -> libsecp256k1

When we run tools/android-test, got error in link period:

xxxx -L/usr/local/lib trezor-crypto/libTrezorCrypto.a  libprotobuf.a  -llog  /usr/local/lib/libsecp256k1.a  -latomic -lm && :
  /Users/bibodeng/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: /usr/local/lib/libsecp256k1.a: no archive symbol table (run ranlib)
  ../../../../../../trezor-crypto/src/ecdsa.c:1211: error: undefined reference to 'secp256k1_context_create'
  ../../../../../../trezor-crypto/src/ecdsa.c:1213: error: undefined reference to 'secp256k1_schnorr_sign'
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.

  Configuring for JNI

two function is undefined and there is no symbols, tell me ranlib. ranlib result:

$ranlib libsecp256k1.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: libsecp256k1.a(/0) size too large (archive member extends past the end of the file)

I run nm -g libsecp256k1.a also said it's truncated or malformed archive.

Please help me to solve this problem, we have stuck several days. Thanks a lot.

guess reason

I read many answer and guess it's reason:

  1. linker will run ranlib before link, but it fail cause there is no symbol ranlib failed because libsecp256k1.a
  2. archive file is too big or maybe not in good format
  3. libsecp256k1.a file is not generated well or ranlib has problems.

codes & config

libsecp256k1: https://github.com/Bitcoin-ABC/secp256k1

./autogen.sh
mkdir build
cd build
../configure --enable-module-schnorr
make
make check
sudo make install

wallet-core: https://github.com/IFWallet/wallet-core/tree/free_cash

git clone git@github.com:IFWallet/wallet-core.git
git checkout free_cash
cd wallet-core
./bootstrap.sh
./tools/android-test

download the codes from github and checkout free_cash branch, run upper cmd will get the same error.

relate answers

I already try this answer, but not work. ndk-no-archive-symbol-table

bibodeng
  • 13
  • 1
  • 7
  • 1
    It looks like you are compiling those dependencies with your host (macOS) compiler, and trying to link them into x86_64 Android binary? That will not work. You need to use the Android cross-compiler for everything. – Botje Feb 28 '20 at 08:25
  • Okay, so can you give some advice about cross-compiler? my project has a library trezor_crypto, it works for ndk, but when using third party library, how to config cross-compiler for third party library? – bibodeng Feb 28 '20 at 12:45
  • See the [Android developer page on cross-compiling](https://developer.android.com/ndk/guides/other_build_systems#autoconf) – Botje Feb 28 '20 at 12:47

0 Answers0