Bitcoin Forum
June 22, 2024, 12:11:08 AM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Using native sipa's secp256k1 shared library in Java's bitcoinj?  (Read 2522 times)
fatefree (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
September 16, 2014, 09:52:16 PM
 #1

I have been trying for almost a day to compile the sipa library here: https://github.com/bitcoin/secp256k1 to no avail. There are some instructions in the bitcoinj client that says:

<p>To build secp256k1 for use with bitcoinj, run `./configure` and `make libjavasecp256k1.so` then copy libjavasecp256k1.so to your system library path or point the JVM to the folder containing it with -Djava.library.path </p>

However there doesn't seem to be a make target for that anymore with the master release on github. I compiled it anyway, and it creates a static library. Is there a way to turn that into a shared object library for a java application?

As a last resort I tried to compile an older version and even managed to create the file libjavasecp256k1.so, but any attempts to load it let to UnsatisfiedLinkErrors that said: unresolved symbol: __gmpn_sub_n or others. It seems like there are missing references to the gmp library.

This is really not my forte so I would appreciate any advice on how to get this working.
bitsta
Hero Member
*****
Offline Offline

Activity: 518
Merit: 500


r00t-dev


View Profile
September 16, 2014, 11:10:08 PM
 #2

I have been trying for almost a day to compile the sipa library here: https://github.com/bitcoin/secp256k1 to no avail. There are some instructions in the bitcoinj client that says:

<p>To build secp256k1 for use with bitcoinj, run `./configure` and `make libjavasecp256k1.so` then copy libjavasecp256k1.so to your system library path or point the JVM to the folder containing it with -Djava.library.path </p>

However there doesn't seem to be a make target for that anymore with the master release on github. I compiled it anyway, and it creates a static library. Is there a way to turn that into a shared object library for a java application?

As a last resort I tried to compile an older version and even managed to create the file libjavasecp256k1.so, but any attempts to load it let to UnsatisfiedLinkErrors that said: unresolved symbol: __gmpn_sub_n or others. It seems like there are missing references to the gmp library.

This is really not my forte so I would appreciate any advice on how to get this working.

afaik static libs are AR-archives. convert them into a
shared lib and call that lib with the java native interface:

Code:
ar -x libsecp256k1.a     //extract archive
gcc -shared *.o -o libsecp256k1.so     //generate shared lib


sources:
http://www.linuxquestions.org/questions/linux-software-2/convert-static-library-filename-a-to-dynamic-shared-object-filename-so-465709/#post2861823
http://jonisalonen.com/2012/calling-c-from-java-is-easy/



p.s. i recommend you to use Bounty Castles custom secp256k1 implementation.
it was also implemented into bitcoinj because of it s runtime improvement.

read:
https://code.google.com/p/bitcoinj/issues/detail?id=509




fatefree (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
September 17, 2014, 03:39:02 AM
 #3

Thank you very much for the suggestions. Unfortunately after converting the archive to a shared library and trying to load it, I'm seeing the same unresolved symbol errors for gmp_sub_n. Here's a question - after running the configure and make commands, am I supposed to be using the libtool to install the library somehow so my Java program can pick it up automatically?
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!