Bitcoin Forum
June 15, 2024, 12:47:44 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Linking error when using bitcoin libs  (Read 63 times)
liorko87 (OP)
Newbie
*
Offline Offline

Activity: 29
Merit: 6


View Profile
February 01, 2021, 03:01:12 PM
 #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::vector<unsigned char >byteRepr(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)
NotATether
Legendary
*
Offline Offline

Activity: 1638
Merit: 6897


bitcoincleanup.com / bitmixlist.org


View Profile WWW
February 02, 2021, 12:11:06 AM
Merited by hugeblack (2), ABCbits (1)
 #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

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!