<p>I was able to run this code:</p>

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

int main() 
{
  bc::ec_secret decoded;
  bc::decode_base16(decoded, "038109007313a5807b2eccc082c8c3fbb988a973cacf1a7df9ce725c31b");
}
</code></pre>

<p>Follow this <a href="https://github.com/libbitcoin/libbitcoin#debianubuntu" rel="nofollow noreferrer">https://github.com/libbitcoin/libbitcoin#debianubuntu</a></p>

<p>After compile it in a /home/x/dir run this:</p>

<pre><code>g++ helloworld.cpp -I/home/dev/bitcoin-lib/include /home/dev/bitcoin-lib/lib/libbitcoin.a /home/dev/bitcoin-lib/lib/libboost_system.a /home/dev/bitcoin-lib/lib/libbitcoin.a /home/dev/bitcoin-lib/lib/libboost_program_options.a /home/dev/bitcoin-lib/lib/libboost_regex.a
</code></pre>

<ul>
<li>we need to tell g++ where are the headers for our #include statement</li>
<li>We need to tell g++ what are the libraries: libbitcoin.a, etc</li>
</ul>

CC BY-SA 4.0
2021-05-19T11:20:44.530Z
Don't forget `-lgmp` when it happens
daparic
CC BY-SA 4.0
2018-09-26T00:34:13.753Z
2018-09-26T00:34:13.753Z
Leonidas Menendez
<p>The book code examples has an accompanying actively maintained github repo <a href="https://github.com/bitcoinbook/bitcoinbook" rel="nofollow noreferrer">here</a>. However, extra care is needed for the <code>libbitcoin</code> library dependency as it has new breaking changes. For example, <code>#include &lt;bitcoin/bitcoin.cpp&gt;</code> has been rename to <code>#include &lt;bitcoin/system.hpp&gt;</code>. And no more <code>bc::ec_point</code>. It is possible to install an older compatible version of <code>libbitcoin</code> library, but I prefer to use the latest version and made some adjustment in <code>addr.cpp</code> example code.</p>
<p>I manually build and installed the <code>libbitcoin</code> library to a custom location <a href="https://github.com/libbitcoin/libbitcoin-system" rel="nofollow noreferrer">as suggested</a>:</p>
<pre><code>mkdir -p /opt/my/libbitcoin/
$ wget https://raw.githubusercontent.com/libbitcoin/libbitcoin/version3/install.sh
$ chmod +x install.sh
$ ./install.sh --prefix=/opt/my/libbitcoin/ --build-boost --disable-shared
</code></pre>
<p>The way I now build <code>addr.cpp</code> is thus:</p>
<pre><code>export PKG_CONFIG_PATH=/opt/my/libbitcoin/lib/pkgconfig/
g++ -o addr addr.cpp $(pkg-config --cflags --libs libbitcoin-system) -lgmp
</code></pre>
<p>And then, running the executable:</p>
<pre><code>$ ./addr
Public key: 0202a406624211f2abbdc68da3df929f938c3399dd79fac1b51b0e4ad1d26a47aa
Address: 1PRTTaJesdNovgne6Ehcdu1fpEdX7913CK
</code></pre>

CC BY-SA 4.0
2021-05-19T11:32:10.527Z
2021-05-19T11:38:51.417Z
2021-05-19T11:38:51.417Z
daparic
<p>Try adding the -std=c++11 flag. </p>

<p>I had the same problem and the following worked for me:</p>

<pre><code>g++ -std=c++11 -o test test.cpp $(pkg-config --cflags --libs libbitcoin)
</code></pre>

CC BY-SA 4.0
2018-06-16T13:27:53.640Z
it didn't work!
Ang
CC BY-SA 4.0
2018-06-16T12:59:08.473Z
2018-06-16T12:59:08.473Z
fotiosp
<p>the libbitcoin library seems to have been installed just fine. 
but the following code can't seem to include bitcoin/bitcoin.hpp</p>

<pre><code>#include&lt;bitcoin/bitcoin.hpp&gt;
#include&lt;iostream&gt;
using namespace bc;
int main() {
    block_type blk = genesis_block();
    std::cout&lt;&lt;encode_hex(hash_block_header(blk.header))&lt;&lt;std::endl;
    return 0;
}
</code></pre>

<p>Error: </p>

<pre><code>g++ -o test test.cpp $(pkg-config --cflags --libs libbitcoin)
test.cpp: In function ‘int main()’:
test.cpp:5:5: error: ‘block_type’ was not declared in this scope
     block_type blk = genesis_block();
     ^~~~~~~~~~
test.cpp:5:5: note: suggested alternative: ‘clock_t’
     block_type blk = genesis_block();
     ^~~~~~~~~~
     clock_t
test.cpp:6:45: error: ‘blk’ was not declared in this scope
     std::cout&lt;&lt;encode_hex(hash_block_header(blk.header))&lt;&lt;std::endl;
                                             ^~~
test.cpp:6:45: note: suggested alternative: ‘brk’
     std::cout&lt;&lt;encode_hex(hash_block_header(blk.header))&lt;&lt;std::endl;
                                             ^~~
                                             brk
test.cpp:6:27: error: ‘hash_block_header’ was not declared in this scope
     std::cout&lt;&lt;encode_hex(hash_block_header(blk.header))&lt;&lt;std::endl;
                           ^~~~~~~~~~~~~~~~~
test.cpp:6:16: error: ‘encode_hex’ was not declared in this scope
     std::cout&lt;&lt;encode_hex(hash_block_header(blk.header))&lt;&lt;std::endl;
                ^~~~~~~~~~
</code></pre>

<libbitcoin>
Not able to use bitcoin/bitcoin.hpp
Ang
# Not able to use bitcoin/bitcoin.hpp

(Asked by: username_0 on 2018-06-16)

the libbitcoin library seems to have been installed just fine.
but the following code can't seem to include bitcoin/bitcoin.hpp

```
#include<bitcoin/bitcoin.hpp>
#include<iostream>
using namespace bc;
int main() {
    block_type blk = genesis_block();
    std::cout<<encode_hex(hash_block_header(blk.header))<<std::endl;
    return 0;
}

```

Error:

```
g++ -o test test.cpp $(pkg-config --cflags --libs libbitcoin)
test.cpp: In function ‘int main()’:
test.cpp:5:5: error: ‘block_type’ was not declared in this scope
     block_type blk = genesis_block();
     ^~~~~~~~~~
test.cpp:5:5: note: suggested alternative: ‘clock_t’
     block_type blk = genesis_block();
     ^~~~~~~~~~
     clock_t
test.cpp:6:45: error: ‘blk’ was not declared in this scope
     std::cout<<encode_hex(hash_block_header(blk.header))<<std::endl;
                                             ^~~
test.cpp:6:45: note: suggested alternative: ‘brk’
     std::cout<<encode_hex(hash_block_header(blk.header))<<std::endl;
                                             ^~~
                                             brk
test.cpp:6:27: error: ‘hash_block_header’ was not declared in this scope
     std::cout<<encode_hex(hash_block_header(blk.header))<<std::endl;
                           ^~~~~~~~~~~~~~~~~
test.cpp:6:16: error: ‘encode_hex’ was not declared in this scope
     std::cout<<encode_hex(hash_block_header(blk.header))<<std::endl;
                ^~~~~~~~~~

```

**Tags:** libbitcoin


---

## 3 answers

### Answer by username_1 on 2018-09-26. Score: 0 | Accepted answer

I was able to run this code:

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

int main() 
{
  bc::ec_secret decoded;
  bc::decode_base16(decoded, "038109007313a5807b2eccc082c8c3fbb988a973cacf1a7df9ce725c31b");
}

```

Follow this <https://github.com/libbitcoin/libbitcoin#debianubuntu>

After compile it in a /home/x/dir run this:

```
g++ helloworld.cpp -I/home/dev/bitcoin-lib/include /home/dev/bitcoin-lib/lib/libbitcoin.a /home/dev/bitcoin-lib/lib/libboost_system.a /home/dev/bitcoin-lib/lib/libbitcoin.a /home/dev/bitcoin-lib/lib/libboost_program_options.a /home/dev/bitcoin-lib/lib/libboost_regex.a

```

* we need to tell g++ where are the headers for our #include statement
* We need to tell g++ what are the libraries: libbitcoin.a, etc

> **Comments:**
> **username_2**: Don't forget `-lgmp` when it happens  

---

### Answer by username_2 on 2021-05-19. Score: 1

The book code examples has an accompanying actively maintained github repo [here](https://github.com/bitcoinbook/bitcoinbook). However, extra care is needed for the `libbitcoin` library dependency as it has new breaking changes. For example, `#include <bitcoin/bitcoin.cpp>` has been rename to `#include <bitcoin/system.hpp>`. And no more `bc::ec_point`. It is possible to install an older compatible version of `libbitcoin` library, but I prefer to use the latest version and made some adjustment in `addr.cpp` example code.

I manually build and installed the `libbitcoin` library to a custom location [as suggested](https://github.com/libbitcoin/libbitcoin-system):

```
mkdir -p /opt/my/libbitcoin/
$ wget https://raw.githubusercontent.com/libbitcoin/libbitcoin/version3/install.sh
$ chmod +x install.sh
$ ./install.sh --prefix=/opt/my/libbitcoin/ --build-boost --disable-shared

```

The way I now build `addr.cpp` is thus:

```
export PKG_CONFIG_PATH=/opt/my/libbitcoin/lib/pkgconfig/
g++ -o addr addr.cpp $(pkg-config --cflags --libs libbitcoin-system) -lgmp

```

And then, running the executable:

```
$ ./addr
Public key: 0202a406624211f2abbdc68da3df929f938c3399dd79fac1b51b0e4ad1d26a47aa
Address: 1PRTTaJesdNovgne6Ehcdu1fpEdX7913CK

```


---

### Answer by username_3 on 2018-06-16. Score: 1

Try adding the -std=c++11 flag.

I had the same problem and the following worked for me:

```
g++ -std=c++11 -o test test.cpp $(pkg-config --cflags --libs libbitcoin)

```

> **Comments:**
> **username_0**: it didn't work!  

---

