Author

Topic: Linking error when using bitcoin libs (Read 64 times)

newbie
Activity: 29
Merit: 6
February 02, 2021, 02:54:35 AM
#3
Thank you for your comment, it's helped a lot.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
February 01, 2021, 07:11:06 PM
#2
You are sourcing include files from the bitcoin source tree without also adding the intermediate static libraries generated by Core during compilation that implement the header file(s) you're including.

In particular, the CSHA256 class lives in src/crypto/sha256.h\cpp which get compiled into src/crypto/libbitcoin_crypto_base.a , a static library that's not exported to /lib after compilation so put this file in your target_link_libraries as well.

Because Core uses makefiles and not CMake, you can't just set CMake to include the whole project folder as a dependency so you have to correlate header files you use with their required static libraries which you can find in src/Makefile.am
newbie
Activity: 29
Merit: 6
February 01, 2021, 10:01:12 AM
#1
I'm trying to build a protocol that uses bitcoin headers and libraries. When I'm creating a PKhash object from a publick key, I'm receiving this error:

Code:
/usr/bin/ld: /home/user/bitcoin/src/libbitcoin_common.a(libbitcoin_common_a-standard.o): in function `CHash160::CHash160()':
/home/user/bitcoin/src/./hash.h:46: undefined reference to `CSHA256::CSHA256()'

The code I created the hash from it from:

Code:
std::vectorbyteRepr(tag.c_str(), tag.c_str() + tag.length());
CPubKey key(byteRepr);
PKHash hash (key);

My CMake file:

Code:
cmake_minimum_required(VERSION 3.16)
project(Bitcoinextension)

set(CMAKE_CXX_STANDARD 11)
set(${CMAKE_CXX_FLAGS} "${CMAKE_CXX_FLAGS} -g3")

include_directories($ENV{HOME}/bitcoin/src $ENV{HOME}/bitcoin/depends/x86_64-pc-linux-gnu/include)
link_directories($ENV{HOME}/bitcoin/src)

add_executable(Bitcoinextension main.cpp Pob.cpp Address.cpp)

target_link_libraries(Bitcoinextension ssl crypto
        $ENV{HOME}/bitcoin/src/libbitcoin_common.a
        $ENV{HOME}/bitcoin/src/libbitcoin_consensus.a
        $ENV{HOME}/bitcoin/src/libbitcoin_cli.a)
Jump to: