bitcoin-core / secp256k1

Optimized C library for EC operations on curve secp256k1
MIT License
2.07k stars 1.01k forks source link

How to compile Secp256K1 .a static library for different architectures #1109

Closed BatterMan-Li closed 1 year ago

BatterMan-Li commented 2 years ago

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

real-or-random commented 2 years ago

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

pjalocha commented 1 year ago

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 ?

real-or-random commented 1 year ago

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.

pjalocha commented 1 year ago

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.

real-or-random commented 1 year ago

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.