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:
- linker will run ranlib before link, but it fail cause there is no
symbol ranlib failed because
libsecp256k1.a
- archive file is too big or maybe not in good format
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