Not able to use bitcoin/bitcoin.hpp

0

1

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;
                ^~~~~~~~~~

nglglhtr

Posted 2018-06-16T12:11:04.833

Reputation: 7

Answers

0

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

Leonidas Menendez

Posted 2018-06-16T12:11:04.833

Reputation: 116

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)

fotiosp

Posted 2018-06-16T12:11:04.833

Reputation: 11

1it didn't work!nglglhtr 2018-06-16T13:27:53.640