secp256k1 icon indicating copy to clipboard operation
secp256k1 copied to clipboard

How to compile Secp256K1 .a static library for different architectures

Open BatterMan-Li opened this issue 2 years ago • 1 comments

At present, my project depends on the secp256k1 library file. Now I need to compile the static library of different architectures for the Android JNI interface. How should I compile it? Please help me, thank you very much

BatterMan-Li avatar May 28 '22 12:05 BatterMan-Li

Set your PATH correctly, for instance:

export PATH="$PATH:/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin

For ARM32 with experimental assembler::

./configure --enable-experimental --with-asm=arm --host=arm-linux-androideabi CC=armv7a-linux-androideabi21-clang CFLAGS="-mthumb -march=armv7-a" CCASFLAGS="-Wa,-mthumb -Wa,-march=armv7-a"

For other architectures, a simpler config should work, for instance:

./configure --host=aarch64-linux-androideabi CC=aarch64-linux-android31-clang

You'll find the .a file in .libs.

Note that there will be many different compilers with different JNI version numbers. You need to select the one you need. 21 and 31 are arbitrary choices above.

related: https://github.com/bitcoin-core/secp256k1/issues/621

real-or-random avatar May 29 '22 15:05 real-or-random

Any dea how to use the library for Arduino/PlatformIO projects ? I need it for HELTEC CubeCell under PlatformIO and Arduio - it starts compiling, but then arm-eabi-none-as is called on the .s files and it wants (I guess a PlatformIO bug) -Os options which fails. Possibly a pure C-version would solve the problem ?

pjalocha avatar Nov 18 '22 23:11 pjalocha

If it's using the ARM assembly and you want pure C, you can force that with ./configure --with-asm=no. But please post the actual output of the tools, that will help.

real-or-random avatar Nov 18 '22 23:11 real-or-random

Thank you, I suspect PlanformIO would not understand any of it because it take the library from the github as it is thus I have no chance to do any configuration.

I tried to copy just the .c file and compile - it did, but then it would not link, I guess not enough flash on my device, so for now I gave up on this and found uECC library which does compile and link. I will see how long it takes to sign. Another problem there is to create recoverable signature but I should be able to work this out.

I will use your library on the receiving end, but there is compiles already, so all is fine.

pjalocha avatar Nov 19 '22 12:11 pjalocha

I tried to copy just the .c file and compile - it did, but then it would not link, I guess not enough flash on my device,

you can ./configure --with-ecmult-window=4 --with-ecmult-gen-precision=2.

Thank you, I suspect PlanformIO would not understand any of it because it take the library from the github as it is thus I have no chance to do any configuration.

Well I don't know how PlanformIO works but if it targets embedded then maybe its package should set these by default? But I can't find the package here: https://registry.platformio.org/search Which package are you using? Maybe you want to create an official package?

If you can set defines/compiler options, then -DECMULT_WINDOW_SIZE=4 -DECMULT_GEN_PREC_BITS=2 should have the same effect.

real-or-random avatar Nov 21 '22 11:11 real-or-random