c++bitcoinraspberry-pi2

Do I have to install `libbitcoin-server` to be able to include `bitcoin.hpp`?


I am reading the book "Mastering Bitcoin" from Antonopoulos and want to compile an example from that book. It does not tell which C++ library needs to be installed for #include <bitcoin/bitcoin.hpp> to work.

#include <bitcoin/bitcoin.hpp>

int main()
{
    // Private secret key.
    bc::ec_secret secret;
    bool success = bc::decode_base16(secret,
        "038109007313a5807b2eccc082c8c3fbb988a973cacf1a7df9ce725c31b14776");
    assert(success);
    // Get public key.
    bc::ec_point public_key = bc::secret_to_public_key(secret);
    std::cout << "Public key: " <> bc::encode_hex(public_key) << std::endl;
    
    // Create Bitcoin address.
    // ... further comments
    
    // Compute hash of public key for P2PKH address.
    const bc::short_hash hash = bc::bitcoin_short_hash(public_key);
    
    bc::data_chunk unencoded_address;
    // Reserve 26 bytes
    // ...
    unencoded_address.reseve(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;
}

Compiling should be done like this:

g++ -o addr addr.cp $(pkg-config --cflags --libs libbitcoin)

Running ./addr should give output:

"Public key: ..."
"Address: ..."

Since there have been a lot of changes to the code base it is unclear what to do with the include. The one of the code is not availlable any more.


Solution

  • What I needed to install was the library libbitcoin or more precisely the "Bitcoin Cross-Platform C++ Development Toolkit" libbitcoin-system.

    But since the best way to solve this was to use the automatic installation script for debian from here:

    $ sudo apt-get install build-essential autoconf automake libtool pkg-config git
    $ wget https://raw.githubusercontent.com/libbitcoin/libbitcoin/version3/install.sh
    $ chmod +x install.sh
    $ ./install.sh --prefix=/home/me/myprefix --build-boost --disable-shared
    

    and this installed the whole libbitcoin system with all dependencies e.g. boost and secp256k1 it also installed libbitcoin-server.

    Installing just parts of it as suggested in another answer did not work for me because of missing dependencies which I could not link properly.


    Regarding the swap I can say that it worked fine with 4GB swapfile on external HDD although the RPi2 has just 20MB/s effective bandwith.


    To be able to use the library I had to give the --static attribute when compiling my program:

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