<p>It seems like pkg-config found libsecp256k1 in the <code>build-libbitcoin</code> directory. which is part of <code>libbitcoin</code>, so they probably build libsecp25k61 there.<br></p>

<p>The reason your code doesn't compile is because your libsecp was compiled with <code>libgmp</code> enabled, now this is a dynamic link. <br>
So if you're trying to create a binary here you need to add <code>-lgmp</code> and if it's not in your system libs you'll need to also give a location to the <code>.so</code> file <br></p>

<p>Another option would be to recompile libsecp with libgmp linking disabled.</p>

CC BY-SA 4.0
2019-09-25T12:36:19.940Z
Thank you very much for your effort! As I understand `libsecp256k1` is a part of `libbitcoin` (as a fork) and thus `build-libbitcoin` should probably contain `libsecp256k1`. Also, when compiling `libbitcoin-system` I used `--disable-shared` so there should be no dynamic link, right?
bomben
CC BY-SA 4.0
2019-09-24T20:16:39.413Z
2019-09-24T20:16:39.413Z
elichai2
<p>I could solve the issue by using the <code>--static</code> attribute:</p>

<p><code>g++ -o addr 69_addr2.cpp $(pkg-config --cflags --libs --static libbitcoin)</code></p>

CC BY-SA 4.0
2019-09-24T12:56:00.233Z
2019-09-24T12:56:00.233Z
bomben
<p>Trying to compile with <code>g++ -o addr 69_addr2.cpp $(pkg-config --cflags --libs libbitcoin)</code> is getting me this error:</p>

<pre><code>/usr/bin/ld: /home/pi/libbitcoininstall/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): in function `secp256k1_num_mod_inverse':
/home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:128: undefined reference to `__gmpn_gcdext'
/usr/bin/ld: /home/pi/libbitcoininstall/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): in function `__gmpn_sub':
/usr/include/arm-linux-gnueabihf/gmp.h:2190: undefined reference to `__gmpn_sub_n'
/usr/bin/ld: /home/pi/libbitcoininstall/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): in function `secp256k1_num_set_bin':
/home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:49: undefined reference to `__gmpn_set_str'
/usr/bin/ld: /home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:49: undefined reference to `__gmpn_set_str'
/usr/bin/ld: /home/pi/libbitcoininstall/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): in function `secp256k1_num_get_bin':
/home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:34: undefined reference to `__gmpn_get_str'
/usr/bin/ld: /home/pi/libbitcoininstall/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): in function `secp256k1_num_set_bin':
/home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:49: undefined reference to `__gmpn_set_str'
/usr/bin/ld: /home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:49: undefined reference to `__gmpn_set_str'
/usr/bin/ld: /home/pi/libbitcoininstall/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): in function `secp256k1_num_get_bin':
/home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:34: undefined reference to `__gmpn_get_str'
collect2: error: ld returned 1 exit status
</code></pre>

<p>Why is there a reference to the <code>build-libbitcoin</code> directory? </p>

<p>I installed <code>libbitcoin</code> in <code>/home/pi/libbitcoininstall</code> and the other directory is just the git where the automatic install script placed all the files. </p>

<p>So, this process should be finished. Why do I even get a print with that directory?</p>

<p>The installation went without error.</p>

<p>I am doing this on a Raspberry (should it matter?)</p>

<p>The small program I try to compile is from a textbook:</p>

<pre><code>#include &lt;bitcoin/bitcoin.hpp&gt;

int main()
{
  bc::ec_secret secret;
  bool success = bc::decode_base16(secret,"038109007313a5807b2eccc082c8c3fbb988a973cacf1a7df9ce725c31v14776");
  assert(success);

  bc::ec_point public_key = bc::secret_to_public_key(secret);
  std::cout &lt;&lt; "Public key: " &lt;&lt; bc::encode_hex(public_key) &lt;&lt; std::endl;

  const bc::short_hash hash = bc::bitcoin_short_hash(public_key);

  bc::data_chunk unencoded_address;
  unencoded_address.reserve(25);
  unencoded_address.push_back(0);
  bc::extend_data(unencoded_address, hash);
  bc::append_checksum(unencoded_address);
  assert(unencoded_address.size() == 25);
  const std::string address = bc::encode_base58(unencoded_address);

  std::cout &lt;&lt; "Address: " &lt;&lt; address &lt;&lt; std::endl;
  return 0;
}
</code></pre>

CC BY-SA 4.0
2019-09-23T11:47:24.357Z
how you have build the libsecp256k1?
vincenzopalazzo
CC BY-SA 4.0
2019-09-23T12:47:54.890Z
It is part of the install script `install.sh` of `libbitcoin` and the developers there argued that using this is the best method to make sure an installation is done properly. See also https://github.com/libbitcoin/libbitcoin-system#building-icu-zlib-png-qrencode-andor-boost
bomben
CC BY-SA 4.0
2019-09-23T12:50:50.223Z
add this to the compile command `-lgmp` ad rebuild the library
vincenzopalazzo
CC BY-SA 4.0
2019-09-23T12:52:42.730Z
Could you please elaborate on the subject? Recompiling will take half a day on my Raspberry so I would like to think about it. :)
bomben
CC BY-SA 4.0
2019-09-23T12:54:29.247Z
look this [issue](https://github.com/mvs-org/metaverse/issues/209) on github, inside it is the solution
vincenzopalazzo
CC BY-SA 4.0
2019-09-23T12:57:36.530Z
Thanks. The install script is 100% automatic. I start `./install.sh` and it finishes after several hours. I am not sure where to add the command. Actually, as you can see, I already appended a message to that closed issue. :)
bomben
CC BY-SA 4.0
2019-09-23T13:06:58.430Z
The directories discussed in the issue you linked are probably special to this github project. I can not find them and also not the `link.txt`. Interestingly, I have the very same error message. Thanks for your input.
bomben
<c++><secp256k1><libbitcoin>
Problem to link to libsecp256k1 on ARM architecture
bomben
# Problem to link to libsecp256k1 on ARM architecture

(Asked by: username_0 on 2019-09-23)

Trying to compile with `g++ -o addr 69_addr2.cpp $(pkg-config --cflags --libs libbitcoin)` is getting me this error:

```
/usr/bin/ld: /home/pi/libbitcoininstall/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): in function `secp256k1_num_mod_inverse':
/home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:128: undefined reference to `__gmpn_gcdext'
/usr/bin/ld: /home/pi/libbitcoininstall/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): in function `__gmpn_sub':
/usr/include/arm-linux-gnueabihf/gmp.h:2190: undefined reference to `__gmpn_sub_n'
/usr/bin/ld: /home/pi/libbitcoininstall/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): in function `secp256k1_num_set_bin':
/home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:49: undefined reference to `__gmpn_set_str'
/usr/bin/ld: /home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:49: undefined reference to `__gmpn_set_str'
/usr/bin/ld: /home/pi/libbitcoininstall/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): in function `secp256k1_num_get_bin':
/home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:34: undefined reference to `__gmpn_get_str'
/usr/bin/ld: /home/pi/libbitcoininstall/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): in function `secp256k1_num_set_bin':
/home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:49: undefined reference to `__gmpn_set_str'
/usr/bin/ld: /home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:49: undefined reference to `__gmpn_set_str'
/usr/bin/ld: /home/pi/libbitcoininstall/lib/libsecp256k1.a(libsecp256k1_la-secp256k1.o): in function `secp256k1_num_get_bin':
/home/pi/GitBen/LibbitcoinBen/build-libbitcoin/secp256k1/src/num_gmp_impl.h:34: undefined reference to `__gmpn_get_str'
collect2: error: ld returned 1 exit status

```

Why is there a reference to the `build-libbitcoin` directory?

I installed `libbitcoin` in `/home/pi/libbitcoininstall` and the other directory is just the git where the automatic install script placed all the files.

So, this process should be finished. Why do I even get a print with that directory?

The installation went without error.

I am doing this on a Raspberry (should it matter?)

The small program I try to compile is from a textbook:

```
#include <bitcoin/bitcoin.hpp>

int main()
{
  bc::ec_secret secret;
  bool success = bc::decode_base16(secret,"038109007313a5807b2eccc082c8c3fbb988a973cacf1a7df9ce725c31v14776");
  assert(success);

  bc::ec_point public_key = bc::secret_to_public_key(secret);
  std::cout << "Public key: " << bc::encode_hex(public_key) << std::endl;

  const bc::short_hash hash = bc::bitcoin_short_hash(public_key);

  bc::data_chunk unencoded_address;
  unencoded_address.reserve(25);
  unencoded_address.push_back(0);
  bc::extend_data(unencoded_address, hash);
  bc::append_checksum(unencoded_address);
  assert(unencoded_address.size() == 25);
  const std::string address = bc::encode_base58(unencoded_address);

  std::cout << "Address: " << address << std::endl;
  return 0;
}

```

**Tags:** c++, secp256k1, libbitcoin

> **Comments:**
> **username_1**: how you have build the libsecp256k1?  
> **username_0**: It is part of the install script `install.sh` of `libbitcoin` and the developers there argued that using this is the best method to make sure an installation is done properly. See also https://github.com/libbitcoin/libbitcoin-system#building-icu-zlib-png-qrencode-andor-boost  
> **username_1**: add this to the compile command `-lgmp` ad rebuild the library  
> **username_0**: Could you please elaborate on the subject? Recompiling will take half a day on my Raspberry so I would like to think about it. :)  
> **username_1**: look this [issue](https://github.com/mvs-org/metaverse/issues/209) on github, inside it is the solution  
> **username_0**: Thanks. The install script is 100% automatic. I start `./install.sh` and it finishes after several hours. I am not sure where to add the command. Actually, as you can see, I already appended a message to that closed issue. :)  
> **username_0**: The directories discussed in the issue you linked are probably special to this github project. I can not find them and also not the `link.txt`. Interestingly, I have the very same error message. Thanks for your input.  

---

## 2 answers

### Answer by username_2 on 2019-09-24. Score: 1

It seems like pkg-config found libsecp256k1 in the `build-libbitcoin` directory. which is part of `libbitcoin`, so they probably build libsecp25k61 there.

The reason your code doesn't compile is because your libsecp was compiled with `libgmp` enabled, now this is a dynamic link.   
So if you're trying to create a binary here you need to add `-lgmp` and if it's not in your system libs you'll need to also give a location to the `.so` file

Another option would be to recompile libsecp with libgmp linking disabled.

> **Comments:**
> **username_0**: Thank you very much for your effort! As I understand `libsecp256k1` is a part of `libbitcoin` (as a fork) and thus `build-libbitcoin` should probably contain `libsecp256k1`. Also, when compiling `libbitcoin-system` I used `--disable-shared` so there should be no dynamic link, right?  

---

### Answer by username_0 on 2019-09-24. Score: 0

I could solve the issue by using the `--static` attribute:

`g++ -o addr 69_addr2.cpp $(pkg-config --cflags --libs --static libbitcoin)`


---

