Giter Site home page Giter Site logo

monero-cpp's Introduction

Monero C++ Library

A C++ library for creating Monero applications using native bindings to monero v0.18.3.3 'Fluorine Fermi'.

  • Supports fully client-side wallets by wrapping wallet2.h.
  • Supports multisig, view-only, and offline wallets.
  • Uses a clearly defined data model and API specification intended to be intuitive and robust.
  • Query wallet transactions, transfers, and outputs by their properties.
  • Receive notifications when wallets sync, send, or receive.
  • Tested by over 100 tests in monero-java and monero-ts using JNI and WebAssembly bindings.

Table of contents

Sample code

// create a wallet from a seed phrase
monero_wallet_config wallet_config;
wallet_config.m_seed = "hefty value later extra artistic firm radar yodel talent future fungal nutshell because sanity awesome nail unjustly rage unafraid cedar delayed thumbs comb custom sanity";
wallet_config.m_path = "MyWalletRestored";
wallet_config.m_password = "supersecretpassword123";
wallet_config.m_network_type = monero_network_type::STAGENET;
wallet_config.m_server = monero_rpc_connection("http://localhost:38081", "superuser", "abctesting123");
wallet_config.m_restore_height = 380104;
wallet_config.m_seed_offset = "";
monero_wallet* wallet_restored = monero_wallet_full::create_wallet(wallet_config);

// synchronize the wallet and receive progress notifications
struct : monero_wallet_listener {
  void on_sync_progress(uint64_t height, uint64_t start_height, uint64_t end_height, double percent_done, const string& message) {
    // feed a progress bar?
  }
} my_sync_listener;
wallet_restored->sync(my_sync_listener);

// start syncing the wallet continuously in the background
wallet_restored->start_syncing();

// get balance, account, subaddresses
string restored_primary = wallet_restored->get_primary_address();
uint64_t balance = wallet_restored->get_balance(); // can specify account and subaddress indices
monero_account account = wallet_restored->get_account(1, true); // get account with subaddresses
uint64_t unlocked_account_balance = account.m_unlocked_balance.get(); // get boost::optional value

// query a transaction by hash
monero_tx_query tx_query;
tx_query.m_hash = "314a0f1375db31cea4dac4e0a51514a6282b43792269b3660166d4d2b46437ca";
vector<shared_ptr<monero_tx_wallet>> txs = wallet_restored->get_txs(tx_query);
shared_ptr<monero_tx_wallet> tx = txs[0];
for (const shared_ptr<monero_transfer> transfer : tx->get_transfers()) {
  bool is_incoming = transfer->is_incoming().get();
  uint64_t in_amount = transfer->m_amount.get();
  int account_index = transfer->m_account_index.get();
}
monero_utils::free(txs);

// query incoming transfers to account 1
monero_transfer_query transfer_query;
transfer_query.m_is_incoming = true;
transfer_query.m_account_index = 1;
vector<shared_ptr<monero_transfer>> transfers = wallet_restored->get_transfers(transfer_query);
monero_utils::free(transfers);

// query unspent outputs
monero_output_query output_query;
output_query.m_is_spent = false;
vector<shared_ptr<monero_output_wallet>> outputs = wallet_restored->get_outputs(output_query);
monero_utils::free(outputs);

// create and sync a new wallet with a random seed phrase
wallet_config = monero_wallet_config();
wallet_config.m_path = "MyWalletRandom";
wallet_config.m_password = "supersecretpassword123";
wallet_config.m_network_type = monero_network_type::STAGENET;
wallet_config.m_server = monero_rpc_connection("http://localhost:38081", "superuser", "abctesting123");
wallet_config.m_language = "English";
monero_wallet* wallet_random = monero_wallet_full::create_wallet(wallet_config);
wallet_random->sync();

// synchronize in the background every 5 seconds
wallet_random->start_syncing(5000);

// get wallet info
string random_seed = wallet_random->get_seed();
string random_primary = wallet_random->get_primary_address();
uint64_t random_height = wallet_random->get_height();
bool random_is_synced = wallet_random->is_synced();

// receive notifications when funds are received, confirmed, and unlocked
struct : monero_wallet_listener {
  void on_output_received(const monero_output_wallet& output) {
    cout << "Wallet received funds!" << endl;
    uint64_t amount = output.m_amount.get();
    string tx_hash = output.m_tx->m_hash.get();
    bool is_confirmed = output.m_tx->m_is_confirmed.get();
    bool is_locked = dynamic_pointer_cast<monero_tx_wallet>(output.m_tx)->m_is_locked.get();
    int account_index = output.m_account_index.get();
    int subaddress_index = output.m_subaddress_index.get();
    FUNDS_RECEIVED = true;
  }
} my_listener;
wallet_random->add_listener(my_listener);

// send funds from the restored wallet to the random wallet
monero_tx_config tx_config;
tx_config.m_account_index = 0;
tx_config.m_address = wallet_random->get_address(1, 0);
tx_config.m_amount = 50000;
tx_config.m_relay = true;
shared_ptr<monero_tx_wallet> sent_tx = wallet_restored->create_tx(tx_config);
bool in_pool = sent_tx->m_in_tx_pool.get();  // true
monero_utils::free(sent_tx);

// mine with 7 threads to push the network along
int num_threads = 7;
bool is_background = false;
bool ignore_battery = false;
wallet_restored->start_mining(num_threads, is_background, ignore_battery);

// wait for the next block to be added to the chain
uint64_t next_height = wallet_random->wait_for_next_block();

// stop mining
wallet_restored->stop_mining();

// create config to send funds to multiple destinations in the random wallet
tx_config = monero_tx_config();
tx_config.m_account_index = 1; // withdraw funds from this account
tx_config.m_subaddress_indices = vector<uint32_t>();
tx_config.m_subaddress_indices.push_back(0);
tx_config.m_subaddress_indices.push_back(1); // withdraw funds from these subaddresses within the account
tx_config.m_priority = monero_tx_priority::UNIMPORTANT; // no rush
tx_config.m_relay = false; // create transaction and relay to the network if true
vector<shared_ptr<monero_destination>> destinations; // specify the recipients and their amounts
destinations.push_back(make_shared<monero_destination>(wallet_random->get_address(1, 0), 50000));
destinations.push_back(make_shared<monero_destination>(wallet_random->get_address(2, 0), 50000));
tx_config.m_destinations = destinations;

// create the transaction, confirm with the user, and relay to the network
shared_ptr<monero_tx_wallet> created_tx = wallet_restored->create_tx(tx_config);
uint64_t fee = created_tx->m_fee.get(); // "Are you sure you want to send ...?"
wallet_restored->relay_tx(*created_tx); // recipient receives notification within 5 seconds
monero_utils::free(created_tx);

// save and close the wallets
wallet_restored->close(true);
wallet_random->close(true);
delete wallet_restored;
delete wallet_random;

Documentation

Using monero-cpp in your project

This project may be compiled as part of another application or built as a shared or static library.

For example, monero-java compiles this project to a shared library to support Java JNI bindings, while monero-ts compiles this project to WebAssembly binaries.

Linux

  1. Clone the project repository if applicable: git clone --recurse-submodules https://github.com/woodser/monero-cpp.git

  2. Update submodules: cd monero-cpp && ./bin/update_submodules.sh

  3. sudo apt update && sudo apt install build-essential cmake pkg-config libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libexpat1-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libboost-chrono-dev libboost-date-time-dev libboost-filesystem-dev libboost-locale-dev libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-system-dev libboost-thread-dev python3 ccache doxygen graphviz nettle-dev libevent-dev

  4. Follow instructions to install unbound for Linux to your home directory (e.g. ~/unbound-1.19.0).

    For example, install expat:

    cd ~
    wget https://github.com/libexpat/libexpat/releases/download/R_2_4_8/expat-2.4.8.tar.bz2
    tar -xf expat-2.4.8.tar.bz2
    sudo rm expat-2.4.8.tar.bz2
    cd expat-2.4.8
    ./configure --enable-static --disable-shared
    make
    sudo make install
    cd ../
    

    For example, install unbound:

    cd ~
    wget https://www.nlnetlabs.nl/downloads/unbound/unbound-1.19.0.tar.gz
    tar xzf unbound-1.19.0.tar.gz
    sudo apt update
    sudo apt install -y build-essential
    sudo apt install -y libssl-dev
    sudo apt install -y libexpat1-dev
    sudo apt-get install -y bison
    sudo apt-get install -y flex
    cd unbound-1.19.0
    ./configure --with-libexpat=/usr --with-ssl=/usr
    make
    sudo make install
    cd ../
    
  5. Build monero-project, located as a submodule at ./external/monero-project. Install dependencies as needed for your system, then build with: make release-static -j8

  6. Link to this library's source files in your application, or build monero-cpp to a shared library in ./build: ./bin/build_libmonero_cpp.sh

macOS

  1. Clone the project repository if applicable: git clone --recurse-submodules https://github.com/woodser/monero-cpp.git

  2. Update submodules: cd monero-cpp && ./bin/update_submodules.sh

  3. Follow instructions to install unbound for macOS to your home directory (e.g. ~/unbound-1.19.0).

    For example:

    cd ~
    wget https://nlnetlabs.nl/downloads/unbound/unbound-1.19.0.tar.gz
    tar xzf unbound-1.19.0.tar.gz
    cd ~/unbound-1.19.0
    ./configure --with-ssl=/opt/homebrew/Cellar/openssl@3/3.2.1/ --with-libexpat=/opt/homebrew/Cellar/expat/2.5.0
    make
    sudo make install
    
  4. Build monero-project, located as a submodule at ./external/monero-project. Install dependencies as needed for your system, then build with: make release-static -j8

  5. Link to this library's source files in your application, or build monero-cpp to a shared library in ./build: ./bin/build_libmonero_cpp.sh

Windows

  1. Download and install MSYS2.

  2. Press the Windows button and launch MSYS2 MINGW64 for 64 bit systems or MSYS2 MINGW32 for 32 bit.

  3. Update packages: pacman -Syu and confirm at prompts.

  4. Relaunch MSYS2 (if necessary) and install dependencies:

    For 64 bit:

    pacman -S mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-unbound mingw-w64-x86_64-protobuf git mingw-w64-x86_64-libusb gettext base-devel
    

    For 32 bit:

    pacman -S  mingw-w64-i686-toolchain make mingw-w64-i686-cmake mingw-w64-i686-boost mingw-w64-i686-openssl mingw-w64-i686-zeromq mingw-w64-i686-libsodium mingw-w64-i686-hidapi mingw-w64-i686-unbound mingw-w64-i686-protobuf git mingw-w64-i686-libusb gettext base-devel
    
  5. Clone repo if installing standalone (skip if building as part of another repo like monero-java or monero-ts): git clone --recursive https://github.com/woodser/monero-cpp.git

  6. Update submodules: cd monero-cpp && ./bin/update_submodules.sh

  7. Build monero-project, located as a submodule at ./external/monero-project. Install dependencies as needed for your system, then build with:

    For 64 bit: make release-static-win64

    For 32 bit: make release-static-win32

  8. Link to this library's source files in your application, or build monero-cpp to a shared library (libmonero-cpp.dll) in ./build: ./bin/build_libmonero_cpp.sh

Running sample code and tests

  1. In CMakeLists.txt, set the flags to build:

      set(BUILD_LIBRARY ON)
      set(BUILD_SAMPLE ON)
      set(BUILD_SCRATCHPAD ON)
      set(BUILD_TESTS ON)
    
  2. ./bin/build_libmonero_cpp.sh

  3. Run the app, for example: ./build/sample_code

Related projects

License

This project is licensed under MIT.

Donations

If this library brings you value, please consider donating.


46FR1GKVqFNQnDiFkH7AuzbUBrGQwz2VdaXTDD4jcjRE8YkkoTYTmZ2Vohsz9gLSqkj5EM6ai9Q7sBoX4FPPYJdGKQQXPVz

monero-cpp's People

Contributors

jbakosi avatar jiwruzim avatar l0nelyc0w avatar woodser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

monero-cpp's Issues

fail to build sample_code

../external-libs/monero-core/libwallet_merged.a(messages-management.pb.cc.o):messages-management.pb.cc:(.text+0x2644): more undefined references to google::protobuf::internal::OnShutdownRun(void (*)(void const*), void const*)' follow ../external-libs/monero-core/libwallet_merged.a(messages-management.pb.cc.o): In function hw::trezor::messages::management::Initialize::MergeFrom(google::protobuf::Message const&)':
messages-management.pb.cc:(.text+0x646d): undefined reference to google::protobuf::internal::ReflectionOps::Merge(google::protobuf::Message const&, google::protobuf::Message*)' ../external-libs/monero-core/libwallet_merged.a(messages-management.pb.cc.o): In function hw::trezor::messages::management::Features::MergeFrom(google::protobuf::Message const&)':
messages-management.pb.cc:(.text+0x696d): undefined reference to google::protobuf::internal::ReflectionOps::Merge(google::protobuf::Message const&, google::protobuf::Message*)' ../external-libs/monero-core/libwallet_merged.a(messages-management.pb.cc.o): In function hw::trezor::messages::management::ApplySettings::MergeFrom(google::protobuf::Message const&)':
messages-management.pb.cc:(.text+0x6bad): undefined reference to google::protobuf::internal::ReflectionOps::Merge(google::protobuf::Message const&, google::protobuf::Message*)' ../external-libs/monero-core/libwallet_merged.a(messages-management.pb.cc.o): In function hw::trezor::messages::management::Ping::MergeFrom(google::protobuf::Message const&)':
messages-management.pb.cc:(.text+0x6d3d): undefined reference to `google::protobuf::internal::ReflectionOps::Merge(google::protobuf::Message const&, google::protobuf::Message*)'
......
......

../external-libs/monero-core/libunbound.a(keyraw.c.o): In function sldns_key_buf2dsa_raw': keyraw.c:(.text+0x144): undefined reference to BN_bin2bn'
keyraw.c:(.text+0x154): undefined reference to BN_bin2bn' keyraw.c:(.text+0x16e): undefined reference to BN_bin2bn'
keyraw.c:(.text+0x189): undefined reference to BN_bin2bn' keyraw.c:(.text+0x1a9): undefined reference to DSA_new'
keyraw.c:(.text+0x1c2): undefined reference to DSA_set0_pqg' keyraw.c:(.text+0x1d3): undefined reference to DSA_set0_key'
keyraw.c:(.text+0x1f6): undefined reference to BN_free' keyraw.c:(.text+0x1fe): undefined reference to BN_free'
keyraw.c:(.text+0x207): undefined reference to BN_free' keyraw.c:(.text+0x20f): undefined reference to BN_free'
keyraw.c:(.text+0x226): undefined reference to DSA_free' keyraw.c:(.text+0x22e): undefined reference to BN_free'
keyraw.c:(.text+0x23c): undefined reference to BN_free' keyraw.c:(.text+0x244): undefined reference to BN_free'
keyraw.c:(.text+0x24d): undefined reference to BN_free' keyraw.c:(.text+0x255): undefined reference to DSA_free'
keyraw.c:(.text+0x25d): undefined reference to BN_free' ../external-libs/monero-core/libunbound.a(keyraw.c.o): In function sldns_key_buf2rsa_raw':
keyraw.c:(.text+0x2b6): undefined reference to BN_new' keyraw.c:(.text+0x2d5): undefined reference to BN_bin2bn'
keyraw.c:(.text+0x2da): undefined reference to BN_new' keyraw.c:(.text+0x2fe): undefined reference to BN_bin2bn'
keyraw.c:(.text+0x303): undefined reference to RSA_new' keyraw.c:(.text+0x31f): undefined reference to RSA_set0_key'
keyraw.c:(.text+0x374): undefined reference to BN_free' keyraw.c:(.text+0x37c): undefined reference to BN_free'
keyraw.c:(.text+0x386): undefined reference to RSA_free' keyraw.c:(.text+0x396): undefined reference to BN_free'
keyraw.c:(.text+0x3a4): undefined reference to BN_free' keyraw.c:(.text+0x3ac): undefined reference to BN_free'
......
......

monero_wallet_core.cpp:(.text._ZN5boost4asio3ssl6detail6engine9put_inputERKNS0_12const_bufferE[_ZN5boost4asio3ssl6detail6engine9put_inputERKNS0_12const_bufferE]+0x4e): undefined reference to BIO_write' CMakeFiles/sample_code.dir/src/wallet/monero_wallet_core.cpp.o: In function boost::asio::ssl::detail::engine::map_error_code(boost::system::error_code&) const':
monero_wallet_core.cpp:(.text._ZNK5boost4asio3ssl6detail6engine14map_error_codeERNS_6system10error_codeE[_ZNK5boost4asio3ssl6detail6engine14map_error_codeERNS_6system10error_codeE]+0x6d): undefined reference to BIO_ctrl' monero_wallet_core.cpp:(.text._ZNK5boost4asio3ssl6detail6engine14map_error_codeERNS_6system10error_codeE[_ZNK5boost4asio3ssl6detail6engine14map_error_codeERNS_6system10error_codeE]+0x9c): undefined reference to SSL_get_shutdown'
CMakeFiles/sample_code.dir/src/wallet/monero_wallet_core.cpp.o: In function boost::asio::ssl::detail::engine::perform(int (boost::asio::ssl::detail::engine::*)(void*, unsigned long), void*, unsigned long, boost::system::error_code&, unsigned long*)': monero_wallet_core.cpp:(.text._ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvmES4_mRNS_6system10error_codeEPm[_ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvmES4_mRNS_6system10error_codeEPm]+0x4c): undefined reference to BIO_ctrl_pending'
monero_wallet_core.cpp:(.text._ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvmES4_mRNS_6system10error_codeEPm[_ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvmES4_mRNS_6system10error_codeEPm]+0x55): undefined reference to ERR_clear_error' monero_wallet_core.cpp:(.text._ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvmES4_mRNS_6system10error_codeEPm[_ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvmES4_mRNS_6system10error_codeEPm]+0xb9): undefined reference to SSL_get_error'
monero_wallet_core.cpp:(.text._ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvmES4_mRNS_6system10error_codeEPm[_ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvmES4_mRNS_6system10error_codeEPm]+0xc1): undefined reference to ERR_get_error' monero_wallet_core.cpp:(.text._ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvmES4_mRNS_6system10error_codeEPm[_ZN5boost4asio3ssl6detail6engine7performEMS3_FiPvmES4_mRNS_6system10error_codeEPm]+0xd4): undefined reference to BIO_ctrl_pending'
CMakeFiles/sample_code.dir/src/wallet/monero_wallet_core.cpp.o: In function boost::asio::ssl::detail::engine::do_shutdown(void*, unsigned long)': monero_wallet_core.cpp:(.text._ZN5boost4asio3ssl6detail6engine11do_shutdownEPvm[_ZN5boost4asio3ssl6detail6engine11do_shutdownEPvm]+0x1f): undefined reference to SSL_shutdown'
monero_wallet_core.cpp:(.text._ZN5boost4asio3ssl6detail6engine11do_shutdownEPvm[_ZN5boost4asio3ssl6detail6engine11do_shutdownEPvm]+0x37): undefined reference to SSL_shutdown' CMakeFiles/sample_code.dir/src/wallet/monero_wallet_core.cpp.o: In function boost::asio::ssl::detail::engine::do_read(void*, unsigned long)':
monero_wallet_core.cpp:(.text._ZN5boost4asio3ssl6detail6engine7do_readEPvm[_ZN5boost4asio3ssl6detail6engine7do_readEPvm]+0x3d): undefined reference to SSL_read' CMakeFiles/sample_code.dir/src/wallet/monero_wallet_core.cpp.o: In function boost::asio::ssl::detail::engine::do_write(void*, unsigned long)':
monero_wallet_core.cpp:(.text._ZN5boost4asio3ssl6detail6engine8do_writeEPvm[_ZN5boost4asio3ssl6detail6engine8do_writeEPvm]+0x3d): undefined reference to `SSL_write'
collect2: error: ld returned 1 exit status

window构建失败

使用MSYS2构建出现以下错误,我该如何解决他

[ 37%] Building CXX object src/common/CMakeFiles/obj_common.dir/dns_utils.cpp.obj
In file included from D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.c
pp:35:
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/threadpool.h:92:10: error: 'deque
' in namespace 'std' does not name a template type
92 | std::deque queue;
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/threadpool.h:33:1: note: 'std::de
que' is defined in header ''; did you forget to '#include '?
32 | #include <boost/thread/thread.hpp>
+++ |+#include
33 | #include
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp: In function 'bool
tools::dns_utils::load_txt_records_from_dns(std::vector<std::__cxx11::basic_string >&, const s
td::vector<std::__cxx11::basic_string >&)':
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:517:20: error: 'set
' is not a member of 'std'
517 | std::vector<std::setstd::string > records;
| ^~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:39:1: note: 'std::s
et' is defined in header ''; did you forget to '#include '?
38 | #include <boost/algorithm/string/join.hpp>
+++ |+#include
39 | #include <boost/optional.hpp>
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:517:20: error: 'set
' is not a member of 'std'
517 | std::vector<std::setstd::string > records;
| ^~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:517:20: note: 'std:
:set' is defined in header ''; did you forget to '#include '?
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:517:35: error: temp
late argument 1 is invalid
517 | std::vector<std::setstd::string > records;
| ^
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:517:35: error: temp
late argument 2 is invalid
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:517:37: error: expe
cted unqualified-id before '>' token
517 | std::vector<std::setstd::string > records;
| ^
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:518:3: error: 'reco
rds' was not declared in this scope
518 | records.resize(dns_urls.size());
| ^~~~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:523:8: error: 'dequ
e' is not a member of 'std'
523 | std::deque avail(dns_urls.size(), false), valid(dns_urls.size(), false);
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:39:1: note: 'std::d
eque' is defined in header ''; did you forget to '#include '?
38 | #include <boost/algorithm/string/join.hpp>
+++ |+#include
39 | #include <boost/optional.hpp>
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:523:14: error: expe
cted primary-expression before 'bool'
523 | std::deque avail(dns_urls.size(), false), valid(dns_urls.size(), false);
| ^~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:528:51: error: 'ava
il' was not declared in this scope
528 | tpool.submit(&waiter,n, dns_urls, &records, &avail, &valid{
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:528:59: error: 'val
id' was not declared in this scope
528 | tpool.submit(&waiter,n, dns_urls, &records, &avail, &valid{
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp: In lambda function
:
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:529:84: error: 'ava
il' is not captured
529 | const auto res = tools::DNSResolver::instance().get_txt_record(dns_urls[n], avail[n],
valid[n]);
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:528:64: note: the l
ambda has no capture-default
528 | tpool.submit(&waiter,n, dns_urls, &records, &avail, &valid{
| ^
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:528:51: note: 'avail' declared here
528 | tpool.submit(&waiter,n, dns_urls, &records, &avail, &valid{
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:529:94: error: 'val
id' is not captured
529 | const auto res = tools::DNSResolver::instance().get_txt_record(dns_urls[n], avail[n],
valid[n]);
|
^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:528:64: note: the l
ambda has no capture-default
528 | tpool.submit(&waiter,n, dns_urls, &records, &avail, &valid{
| ^
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:528:59: note: 'valid' declared here
528 | tpool.submit(&waiter,n, dns_urls, &records, &avail, &valid{
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:531:10: error: 'rec
ords' is not captured
531 | records[n].insert(s);
| ^~~~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:528:64: note: the l
ambda has no capture-default
528 | tpool.submit(&waiter,n, dns_urls, &records, &avail, &valid{
| ^
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:518:3: note: 'records' declared here
518 | records.resize(dns_urls.size());
| ^~~~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp: In function 'bool
tools::dns_utils::load_txt_records_from_dns(std::vector<std::__cxx11::basic_string >&, const s
td::vector<std::__cxx11::basic_string >&)':
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:540:10: error: 'ava
il' was not declared in this scope
540 | if (!avail[cur_index])
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:545:10: error: 'val
id' was not declared in this scope
545 | if (!valid[cur_index])
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:574:25: error: 'set
' is not a member of 'std'
574 | typedef std::map<std::setstd::string, uint32_t> map_t;
| ^~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:574:25: note: 'std:
:set' is defined in header ''; did you forget to '#include '?
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:574:25: error: 'set
' is not a member of 'std'
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:574:25: note: 'std:
:set' is defined in header ''; did you forget to '#include '?
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:574:40: error: wron
g number of template arguments (1, should be at least 2)
574 | typedef std::map<std::setstd::string, uint32_t> map_t;
| ^
In file included from D:/msys2/mingw64/include/c++/12.2.0/map:61,
from D:/msys2/home/yangys/monero-cpp/external/monero-project/external/easylogging++
/easylogging++.h:405,
from D:/msys2/home/yangys/monero-cpp/external/monero-project/contrib/epee/include/m
isc_log_ex.h:35,
from D:/msys2/home/yangys/monero-cpp/external/monero-project/contrib/epee/include/i
nclude_base_utils.h:32,
from D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.c
pp:34:
D:/msys2/mingw64/include/c++/12.2.0/bits/stl_map.h:100:11: note: provided for 'template<class _Key,
class Tp, class Compare, class Alloc> class std::map'
100 | class map
| ^~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:574:41: error: expe
cted unqualified-id before ',' token
574 | typedef std::map<std::setstd::string, uint32_t> map_t;
| ^
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:574:51: error: expe
cted initializer before '>' token
574 | typedef std::map<std::setstd::string, uint32_t> map_t;
| ^
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:575:3: error: 'map

t' was not declared in this scope
575 | map_t record_count;
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:579:9: error: 'reco
rd_count' was not declared in this scope
579 | ++record_count[e];
| ^~~~~~~~~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:582:3: error: 'map

t' is not a class, namespace, or enumeration
582 | map_t::const_iterator good_record = record_count.end();
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:583:8: error: 'map

t' is not a class, namespace, or enumeration
583 | for (map_t::const_iterator i = record_count.begin(); i != record_count.end(); ++i)
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:583:56: error: 'i'
was not declared in this scope
583 | for (map_t::const_iterator i = record_count.begin(); i != record_count.end(); ++i)
| ^
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:583:61: error: 'rec
ord_count' was not declared in this scope
583 | for (map_t::const_iterator i = record_count.begin(); i != record_count.end(); ++i)
| ^~~~~~~~~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:585:9: error: 'good
_record' was not declared in this scope; did you mean 'good_records'?
585 | if (good_record == record_count.end() || i->second > good_record->second)
| ^~~~~~~~~~~
| good_records
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:589:23: error: 'goo
d_record' was not declared in this scope; did you mean 'good_records'?
589 | MDEBUG("Found " << (good_record == record_count.end() ? 0 : good_record->second) << "/" <<
dns_urls.size() << " matching records from " << num_valid_records << " valid records");
| ^~~~~~~~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/contrib/epee/include/misc_log_ex.h:45:93: no
te: in definition of macro 'MCLOG_TYPE'
45 | el::base::Writer(level, color, FILE, LINE, ELPP_FUNC, type).construct(cat) <<
x;
|
^
D:/msys2/home/yangys/monero-cpp/external/monero-project/contrib/epee/include/misc_log_ex.h:56:24: no
te: in expansion of macro 'MCLOG'
56 | #define MCDEBUG(cat,x) MCLOG(el::Level::Debug,cat, el::Color::Default, x)
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/contrib/epee/include/misc_log_ex.h:78:19: no
te: in expansion of macro 'MCDEBUG'
78 | #define MDEBUG(x) MCDEBUG(MONERO_DEFAULT_LOG_CATEGORY,x)
| ^~~~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:589:3: note: in exp
ansion of macro 'MDEBUG'
589 | MDEBUG("Found " << (good_record == record_count.end() ? 0 : good_record->second) << "/" <<
dns_urls.size() << " matching records from " << num_valid_records << " valid records");
| ^~~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:589:38: error: 'rec
ord_count' was not declared in this scope
589 | MDEBUG("Found " << (good_record == record_count.end() ? 0 : good_record->second) << "/" <<
dns_urls.size() << " matching records from " << num_valid_records << " valid records");
| ^~~~~~~~~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/contrib/epee/include/misc_log_ex.h:45:93: no
te: in definition of macro 'MCLOG_TYPE'
45 | el::base::Writer(level, color, FILE, LINE, ELPP_FUNC, type).construct(cat) <<
x;
|
^
D:/msys2/home/yangys/monero-cpp/external/monero-project/contrib/epee/include/misc_log_ex.h:56:24: no
te: in expansion of macro 'MCLOG'
56 | #define MCDEBUG(cat,x) MCLOG(el::Level::Debug,cat, el::Color::Default, x)
| ^~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/contrib/epee/include/misc_log_ex.h:78:19: no
te: in expansion of macro 'MCDEBUG'
78 | #define MDEBUG(x) MCDEBUG(MONERO_DEFAULT_LOG_CATEGORY,x)
| ^~~~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:589:3: note: in exp
ansion of macro 'MDEBUG'
589 | MDEBUG("Found " << (good_record == record_count.end() ? 0 : good_record->second) << "/" <<
dns_urls.size() << " matching records from " << num_valid_records << " valid records");
| ^~~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:590:7: error: 'good
_record' was not declared in this scope; did you mean 'good_records'?
590 | if (good_record == record_count.end() || good_record->second < dns_urls.size() / 2 + 1)
| ^~~~~~~~~~~
| good_records
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:590:22: error: 'rec
ord_count' was not declared in this scope
590 | if (good_record == record_count.end() || good_record->second < dns_urls.size() / 2 + 1)
| ^~~~~~~~~~~~
D:/msys2/home/yangys/monero-cpp/external/monero-project/src/common/dns_utils.cpp:597:23: error: 'goo
d_record' was not declared in this scope; did you mean 'good_records'?
597 | for (const auto &s: good_record->first)
| ^~~~~~~~~~~
| good_records
make[3]: *** [src/common/CMakeFiles/obj_common.dir/build.make:104: src/common/CMakeFiles/obj_common.dir/dns_utils.cpp.obj] Error 1
make[2]: *** [CMakeFiles/Makefile2:1596: src/common/CMakeFiles/obj_common.dir/all] Error 2
make[1]: *** [Makefile:146: all] Error 2
make[1]: Leaving directory '/home/yangys/monero-cpp/external/monero-project/build/release'
make: *** [Makefile:155: release-static-win64] Error 2

Missing libwallet-crypto.a

Hi there,
I am struggling to build the library on my Apple M1 (I managed to build on Linux, Apple Intel, and using buildx of docker). I had to make some tweaks to build monero statically (tip from monero-project/monero#8332) but, I can't find why the library libwallet-crypto.a wasn't built by monero.

Tried to upload the monero compilation logs somewhere but it was too big. Let me know if you need an specific part of it.

monero-cpp compilation:

-- The C compiler identification is Clang 14.0.6
-- The CXX compiler identification is Clang 14.0.6
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/homebrew/opt/llvm/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/homebrew/opt/llvm/bin/clang - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- EXTERNAL_LIBS_DIR:/Users/aquila.freitas/Projects/Personal/Monero/monero-cpp/external-libs
-- EXTRA_LIBRARIES:/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/IOKit.framework/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/CoreFoundation.framework/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/AppKit.framework
-- Found Protobuf: /opt/homebrew/lib/libprotobuf.dylib (found version "3.21.2")
-- Protobuf lib: /opt/homebrew/lib/libprotobuf.dylib, inc: /opt/homebrew/include, protoc: /opt/homebrew/bin/protoc
-- Using Boost include dir at /opt/homebrew/include
-- Using OpenSSL found at /opt/homebrew/opt/openssl@3
-- Found OpenSSL: /opt/homebrew/opt/openssl@3/lib/libcrypto.dylib (found version "3.0.5")
-- Using OpenSSL include dir at /opt/homebrew/opt/openssl@3/include
-- Using libsodium library at /opt/homebrew/lib/libsodium.dylib
-- Found HIDAPI: /opt/homebrew/lib/libhidapi.dylib
-- Using HIDAPI include dir at /opt/homebrew/include/hidapi
-- Using monero-project build:/Users/aquila.freitas/Projects/Personal/Monero/monero-cpp/external/monero-project/build/release
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/aquila.freitas/Projects/Personal/Monero/monero-cpp/build
[ 12%] Building CXX object CMakeFiles/monero-cpp.dir/src/utils/gen_utils.cpp.o
[ 25%] Building CXX object CMakeFiles/monero-cpp.dir/src/utils/monero_utils.cpp.o
[ 37%] Building CXX object CMakeFiles/monero-cpp.dir/src/daemon/monero_daemon_model.cpp.o
[ 50%] Building CXX object CMakeFiles/monero-cpp.dir/src/daemon/monero_daemon.cpp.o
[ 62%] Building CXX object CMakeFiles/monero-cpp.dir/src/wallet/monero_wallet_model.cpp.o
[ 75%] Building CXX object CMakeFiles/monero-cpp.dir/src/wallet/monero_wallet_keys.cpp.o
[ 87%] Building CXX object CMakeFiles/monero-cpp.dir/src/wallet/monero_wallet_full.cpp.o
In file included from /Users/aquila.freitas/Projects/Personal/Monero/monero-cpp/src/wallet/monero_wallet_full.cpp:60:
/Users/aquila.freitas/Projects/Personal/Monero/monero-cpp/external/monero-project/src/wallet/wallet_rpc_server_commands_defs.h:51:9: warning: 'WALLET_RPC_VERSION_MINOR' macro redefined [-Wmacro-redefined]
#define WALLET_RPC_VERSION_MINOR 24
        ^
/Users/aquila.freitas/Projects/Personal/Monero/monero-cpp/external/monero-project/src/wallet/wallet_rpc_server_commands_defs.h:50:9: note: previous definition is here
#define WALLET_RPC_VERSION_MINOR 22
        ^
1 warning generated.
gmake[2]: *** No rule to make target '../external/monero-project/build/release/src/crypto/wallet/libwallet-crypto.a', needed by 'libmonero-cpp.dylib'.  Stop.
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/monero-cpp.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2

Windows build error

Last step cd ../../ && ./bin/build_libmonero_cpp.sh failed with error

[2/8] Building CXX object CMakeFiles/monero-cpp.dir/src/utils/gen_utils.cpp.obj
FAILED: CMakeFiles/monero-cpp.dir/src/utils/gen_utils.cpp.obj
C:\msys64\mingw64\bin\c++.exe -DHAVE_HIDAPI -DWIN32_LEAN_AND_MEAN -D_GLIBCXX_USE_NANOSLEEP=1 -Dmoner
o_cpp_EXPORTS -IC:/msys64/home/HP/monero-java/external/monero-cpp/src -IC:/msys64/home/HP/monero-jav
a/external/monero-cpp/external/monero-project/contrib/epee/include -IC:/msys64/home/HP/monero-java/e
xternal/monero-cpp/external/monero-project/external -IC:/msys64/home/HP/monero-java/external/monero-
cpp/external/monero-project/external/easylogging++ -IC:/msys64/home/HP/monero-java/external/monero-c
pp/external/monero-project/external/rapidjson/include -IC:/msys64/home/HP/monero-java/external/moner
o-cpp/external/monero-project/src -IC:/msys64/home/HP/monero-java/external/monero-cpp/external/moner
o-project/src/wallet -IC:/msys64/home/HP/monero-java/external/monero-cpp/external/monero-project/src
/wallet/api -IC:/msys64/home/HP/monero-java/external/monero-cpp/external/monero-project/src/hardfork
s -IC:/msys64/home/HP/monero-java/external/monero-cpp/external/monero-project/src/crypto/crypto_ops_
builder/include -IC:/msys64/home/HP/monero-java/external/monero-cpp/external/libsodium/include/sodiu
m -IC:/msys64/mingw64/include/hidapi -Wa,-mbig-obj -O2 -fPIC -std=c++14 -F/Library/Frameworks -pthre
ad -lcrypto -lcrypt32 -MD -MT CMakeFiles/monero-cpp.dir/src/utils/gen_utils.cpp.obj -MF CMakeFiles\m
onero-cpp.dir\src\utils\gen_utils.cpp.obj.d -o CMakeFiles/monero-cpp.dir/src/utils/gen_utils.cpp.obj
 -c C:/msys64/home/HP/monero-java/external/monero-cpp/src/utils/gen_utils.cpp
In file included from C:/msys64/home/HP/monero-java/external/monero-cpp/src/utils/gen_utils.cpp:53:
C:/msys64/home/HP/monero-java/external/monero-cpp/src/utils/gen_utils.h: In function 'void gen_utils
::wait_for(uint64_t)':
C:/msys64/home/HP/monero-java/external/monero-cpp/src/utils/gen_utils.h:88:10: error: 'std::this_thr
ead' has not been declared
   88 |     std::this_thread::sleep_for(std::chrono::milliseconds(duration_ms));
      |          ^~~~~~~~~~~

How to link and compile sample_code with the shared library ?

Hi Woodser, I'm new to c++ and want to try the monero library, the build is successful i believe (no errors), I followed all the steps, but I have never used a library (outside the standard library) and have no clue what to put after g++ in the command line.

In Home/monero-cpp/test there is the file sample_code.cpp that i want to run. In step 7 you say "Link to this library's source files in your application", Do you mean the source files in Home/monero-cpp/src, and what does linking mean in this context do i have to somehow tell the compiler the path to these files, and how will my program use the monero-project functions, how should i tell the compiler to check wallet2.cpp and all the other files.

You also say "build as a shared library in ./build/", running the shell script build_libmonero_cpp.sh just creates in Home/monero-cpp/external/monero-project/build what is already in the release folder. So is the step necessary ?

Finally, the closest thing to a library that I could comprehend is the static library libwallet.a in .../monero-project/build/lib (static libraries are not shared libraries ?), and the other .a files in build/src folders. But I can't find shared library file ending with .so and i find no trace of the libwallet_merged.a file that you describe in step 5.

And even if i found the right .so file, i couldn't tell how to link it with the a basic test program. I've read ressources about static and dynamic linking but still can't figure out anything. So please if you could give me some help and direction please. (I'm on Ubuntu)

Native crash when I set priority

That will through a native exception when I create a tx and set a priority.
I will get the abort message like below

terminating with uncaught exception of type boost::wrapexceptboost::property_tree::ptree_bad_data: conversion of data to type "j" failed

How could I fix it?

Libboost v1.74 - error: call of overloaded addJsonMember is ambiguous

Compilation error with the new lib boost 1.74

monero_wallet_model.cpp:1140:120: error: call of overloaded ‘addJsonMember(const char [9], const monero::monero_tx_priority&, rapidjson::GenericDocument<rapidjson::UTF8<> >::AllocatorType&, rapidjson::Value&, rapidjson::Value&)’ is ambiguous
 1140 |     if (m_priority != boost::none) monero_utils::addJsonMember("priority", m_priority.get(), allocator, root, value_num);

When I use msys2 to operate 'Using this library in your project' on window, I get the following exception, I am not familiar with cmake and don't know how to solve this problem.

I modified 'cd $MONERO_CPP/external/monero-project && make release-static -j8 && make release-static -j8' of operation 5 to 'cd $MONERO_CPP/external/monero-project && make release-static-win64 - j8 && make release-static-win64 -j8'.

Execute operation 6 to the following exception.

[ 98%] Linking CXX executable ../../bin/monero-gen-trusted-multisig.exe
[ 98%] Linking CXX executable ../../bin/monero-blockchain-mark-spent-outputs.exe
make[3]: Leaving directory '/monero-java/external/monero-cpp/external/monero-project/build/release'
[ 98%] Built target blockchain_blackball
make[3]: Leaving directory '/monero-java/external/monero-cpp/external/monero-project/build/release'
[ 98%] Built target gen_multisig
[ 98%] Linking CXX executable ../../bin/monero-wallet-cli.exe
make[3]: Leaving directory '/monero-java/external/monero-cpp/external/monero-project/build/release'
[ 98%] Built target simplewallet
[100%] Linking CXX executable ../../bin/monero-wallet-rpc.exe
make[3]: Leaving directory '/monero-java/external/monero-cpp/external/monero-project/build/release'
[100%] Built target wallet_rpc_server
make[2]: Leaving directory '/monero-java/external/monero-cpp/external/monero-project/build/release'
make[1]: Leaving directory '/monero-java/external/monero-cpp/external/monero-project/build/release'
-- Building for: Ninja
-- The C compiler identification is GNU 12.1.0
-- The CXX compiler identification is GNU 12.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/software/msys2/mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/software/msys2/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- EXTERNAL_LIBS_DIR:D:/software/msys2/monero-java/external/monero-cpp/external-libs
-- EXTRA_LIBRARIES:setupapi
Protobuf_INCLUDE_DIR------------->>>D:/software/msys2/mingw64/include/protobuf-3.21.2
-- Found Protobuf: usr/bin/ (found version "3.21.2")
Protobuf_INCLUDE_DIR------------->>>D:/software/msys2/mingw64/include/protobuf-3.21.2
-- Could NOT find Protobuf (missing: Protobuf_INCLUDE_DIR) (found version "3.21.2")
-- Protobuf lib: usr/bin/, inc: , protoc: D:/software/protoc/bin/protoc.exe
-- Using Boost include dir at D:/software/msys2/mingw64/include
-- Found OpenSSL: D:/software/msys2/mingw64/lib/libcrypto.dll.a (found version "1.1.1q")
-- Using OpenSSL include dir at D:/software/msys2/mingw64/include
-- Using libsodium library at D:/software/msys2/mingw64/lib/libsodium.dll.a
-- Found HIDAPI: D:/software/msys2/mingw64/lib/libhidapi.dll.a
-- Using HIDAPI include dir at D:/software/msys2/mingw64/include/hidapi
-- Using monero-project build:D:/software/msys2/monero-java/external/monero-cpp/external/monero-project/build/release
-- Configuring done
-- Generating done
-- Build files have been written to: D:/software/msys2/monero-java/external/monero-cpp/build
ninja: error: '../external/monero-project/build/release/src/crypto/wallet/libwallet-crypto.a', needed by 'libmonero-cpp.dll', missing and no known rule to make it

Add LICENSE file

The README states this work is licensed under the MIT license. Please add the actual license in a dedicated LICENSE file, to avoid possible future issues.

Issue building shared library

After running make release-static on the monero project, I ran ./bin/build_libmonero_cpp.sh to build the shared libraries. This resulted in the following output:
output.txt

How to build monero-cpp for MSVC x64 2019 compiler?

I am experiencing some difficulties with compiling this library for my project, which also compiles under Windows.

As I understand it, under Windows i can only compile using MSYS2 and MINGW compiler, which is bad for me. MSVC and MINGW can at least have different ABIs and the static library files themselves have different extensions.

I had an idea to compile the project with the MSVC compiler, but I ran into a problem. I was unable to compile the "libunbound" library. I think "libunbound" is basically not designed to be compiled through MSVC.

Is there any way I can compile the project and at least get the *.lib static libraries so I can use "monero-cpp" in my project?

"monero-cpp" does not compile on Linux (Ubuntu 20)

Compiling on Ubuntu-20:

Section: Using this library in your project

From the description:
Link to this library's source files in your application or build as a shared library in ./build/: $ cd $MONERO_CPP && ./bin/build_libmonero_cpp.sh

Gives the following error:

[ 95%] Built target simplewallet
[ 95%] Built target blockchain_blackball
[ 96%] Built target gen_multisig
[ 97%] Built target wallet_rpc_server
-- EXTERNAL_LIBS_DIR:/home/mike/code/wrappers/monero-cpp/external-libs
-- EXTRA_LIBRARIES:
-- Protobuf lib: /usr/lib/x86_64-linux-gnu/libprotobuf.so, inc: /usr/include, protoc: /usr/bin/protoc
-- Using Boost include dir at /usr/include
-- Using OpenSSL include dir at /usr/include
-- Using libsodium library at /usr/lib/x86_64-linux-gnu/libsodium.so
-- Using HIDAPI include dir at /usr/include/hidapi
-- Using monero-project build:/home/mike/code/wrappers/monero-cpp/external/monero-project/build/release
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mike/code/wrappers/monero-cpp/build
make[2]: *** No rule to make target '../external/monero-project/build/release/lib/libwallet_merged.a', needed by 'scratchpad'.  Stop.
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/scratchpad.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

I expected it to compile by default.

Port test suite from Java library

This issue requests porting this library's Java counterpart's JUnit test suite to C++ for use in this library.

Currently, the Java library tests the C++ library through the JNI interface. A native C++ test suite would allow more thorough testing of C++ references and remove depending on the Java project for tests.

Undefined reference to strlcpy and Proto* when building monero-project

I'm having trouble compiling monero-project in Ubuntu (both 20.04 and 22.04) due to some undefined reference errors:

[ 95%] Linking CXX executable ../../bin/monerod
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libzmq.a(libzmq_la-ws_engine.o): in function `zmq::ws_engine_t::server_handshake()':
(.text+0x1a6b): undefined reference to `strlcpy'
/usr/bin/ld: (.text+0x1ab9): undefined reference to `strlcpy'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libzmq.a(libzmq_la-ws_engine.o): in function `zmq::ws_engine_t::client_handshake()':
(.text+0x24a5): undefined reference to `strlcpy'
/usr/bin/ld: (.text+0x24cc): undefined reference to `strlcpy'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libnorm.a(normApi.cpp.o): in function `NormInstance::SetCacheDirectory(char const*)':
(.text+0xe0): undefined reference to `ProtoDispatcher::SuspendThread()'
/usr/bin/ld: (.text+0x153): undefined reference to `ProtoDispatcher::ResumeThread()'
...

Am I missing anything and is there anyway to resolve this issue?

Segfault when creating in-memory wallet using `monero_wallet_full::create_wallet()`

This code, which is now deprecated works perfectly fine:

monero_wallet_obj = std::unique_ptr<monero_wallet_full>(monero_wallet_full::create_wallet_from_mnemonic("", "", network_type, mnemonic));

But I'm having an issue after transitioning to the new monero_wallet_full::create_wallet() function that uses monero::monero_wallet_config

monero::monero_wallet_config wallet_config_obj;
wallet_config_obj.m_path = "";
wallet_config_obj.m_password = "";
wallet_config_obj.m_network_type = network_type;
wallet_config_obj.m_mnemonic = mnemonic;
    
monero_wallet_obj = std::unique_ptr<monero_wallet_full>(monero_wallet_full::create_wallet (wallet_config_obj, nullptr));

The second code snippet above produces this error:

/usr/include/boost/optional/optional.hpp:1211: boost::optional<T>::reference_const_type boost::optional<T>::get() const [with T = long unsigned int; boost::optional<T>::reference_const_type = const long unsigned int&]: Assertion `this->is_initialized()' failed.
Aborted (core dumped)

Could I be doing something wrong here?

Automate build of this project

This issue requests help automating the build of this project.

For comparison, Cake Wallet's automated build process is documented here: https://github.com/fotolockr/CakeWallet

And Monerujo's build process is documented here: https://github.com/m2049r/xmrwallet/blob/master/doc/BUILDING-external-libs.md

Ideally this project would contain a shell script to be executed one time which downloads and builds all dependencies, but any contributions that get closer to that are welcome.

Build issue

Trying to compile this by following the readme.

I'm getting this error when I run bin/build_libmonero_cpp.sh. I'm not that great at C++, I suppose I'm missing some dependency?

[  3%] Building CXX object CMakeFiles/scratchpad.dir/src/wallet/monero_wallet_keys.cpp.o
In file included from /home/user/git/monero-java/external/monero-cpp-library/src/wallet/monero_wallet_keys.h:55,
                 from /home/user/git/monero-java/external/monero-cpp-library/src/wallet/monero_wallet_keys.cpp:53:
/home/user/git/monero-java/external/monero-cpp-library/src/wallet/monero_wallet.h:397:13: error: ‘set’ does not name a type
  397 |     virtual set<monero_wallet_listener*> get_listeners() {
      |             ^~~
make[2]: *** [CMakeFiles/scratchpad.dir/build.make:161: CMakeFiles/scratchpad.dir/src/wallet/monero_wallet_keys.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:100: CMakeFiles/scratchpad.dir/all] Error 2
make: *** [Makefile:104: all] Error 2

I tried compiling in two ways:

  • monero-cpp-library v0.2.0 with monero core at v0.15.0.1
  • monero-cpp-library master with monero master

Both give the same problem.

This is what ./external-libs/ looks like:

.
├── boost
│   ├── libboost_atomic.a
│   ├── libboost_chrono.a
│   ├── libboost_container.a
│   ├── libboost_context.a
│   ├── libboost_contract.a
│   ├── libboost_coroutine.a
│   ├── libboost_date_time.a
│   ├── libboost_exception.a
│   ├── libboost_fiber.a
│   ├── libboost_filesystem.a
│   ├── libboost_graph.a
│   ├── libboost_iostreams.a
│   ├── libboost_locale.a
│   ├── libboost_log.a
│   ├── libboost_log_setup.a
│   ├── libboost_math_c99.a
│   ├── libboost_math_c99f.a
│   ├── libboost_math_c99l.a
│   ├── libboost_math_tr1.a
│   ├── libboost_math_tr1f.a
│   ├── libboost_math_tr1l.a
│   ├── libboost_numpy38.a
│   ├── libboost_prg_exec_monitor.a
│   ├── libboost_program_options.a
│   ├── libboost_python38.a
│   ├── libboost_random.a
│   ├── libboost_regex.a
│   ├── libboost_serialization.a
│   ├── libboost_stacktrace_addr2line.a
│   ├── libboost_stacktrace_basic.a
│   ├── libboost_stacktrace_noop.a
│   ├── libboost_system.a
│   ├── libboost_test_exec_monitor.a
│   ├── libboost_thread.a
│   ├── libboost_timer.a
│   ├── libboost_type_erasure.a
│   ├── libboost_unit_test_framework.a
│   ├── libboost_wave.a
│   └── libboost_wserialization.a
├── hidapi
│   └── libhidapi-libusb.a
├── libsodium
│   └── libsodium.a
└── openssl
    ├── libcrypto.a
    └── libssl.a

libwallet.a and libwallet_merged.a are in ./external/monero-core/build/release/lib

Error when linking a static library

I'm having some trouble linking the monero-cpp library to my simple project. I created a simple test project to help you figure out what exactly is going wrong. We are talking about MSYS2 MinGW64 assembly on Windows 10 x64.
And so what needs to be done:

git clone [email protected]:sdcwen/monero-test.git
cd ./monero-test/
git submodule update --init
cd ./external/monero-cpp/
git checkout v0.7.6
cd ../../

Then you need to replace monero-test/external/monero-cpp/CMakeLists.txt with the monero-test/patch/CMakeLists.txt file. This file contains some fixes that allow you to add monero-cpp via add_subdirectory to your project.

-set(MONERO_PROJECT "${CMAKE_SOURCE_DIR}/external/monero-project" CACHE STRING "Monero project source directory")
+set(MONERO_PROJECT "${CMAKE_CURRENT_LIST_DIR}/external/monero-project" CACHE STRING "Monero project source directory")
...
-include_directories(src/)
+include_directories(${CMAKE_CURRENT_LIST_DIR}/src/)
...
-set(EXTERNAL_LIBS_DIR ${CMAKE_SOURCE_DIR}/external-libs)
+set(EXTERNAL_LIBS_DIR ${CMAKE_CURRENT_LIST_DIR}/external-libs)

With the help of ${CMAKE_CURRENT_LIST_DIR} I simply indicate that I want to build the rest of the paths relative to the current position of the file in the system. If this is not done, then add_subdirectory will not work correctly.

I also change the building of the dynamic library to a static one. I think this should not break anything, because all other libraries are imported from monero-project as static and the monero-cpp library itself can also be static.

-  add_library(monero-cpp SHARED ${LIBRARY_SRC_FILES})
+  add_library(monero-cpp STATIC ${LIBRARY_SRC_FILES})

Okay now we are ready to assemble. I use a customized QtCreator for building, which pulls the MSYS2 MinGW64 environment (which can be taken in monero-test/env/msys64/mingw64/paths.txt). Or you can do it through the MSYS2 MinGW64 terminal:

mkdir .build
cd ./.build
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug ..
cmake --build . --target all

And now I'm getting an error that I can't do anything about and don't understand why it's happening at all:

[27/28] Linking CXX executable monero-test.exe
FAILED: monero-test.exe
cmd.exe /C "cd . && C:\msys64\mingw64\bin\c++.exe -g  @CMakeFiles\monero-test.rsp -o monero-test.exe -Wl,--out-implib,libmonero-test.dll.a -Wl,--major-image-version,0,--minor-image-version,0  && cd ."
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/monero-test/external/monero-cpp/external/monero-project/build/release/src/device_tr
ezor/libdevice_trezor.a(protocol.cpp.obj):protocol.cpp:(.text+0x43cb): undefined reference to `hmac_keccak_hash'
collect2.exe: error: ld returned 1 exit status
[28/28] Linking CXX executable external\monero-cpp\scratchpad.exe
ninja: build stopped: subcommand failed.

In fact, I simply copied the contents of monero-test/external/monero-cpp/test/sample_code.cpp into my main.cpp file. And it is worth noting that sample_code.cpp itself compiles without problems.
And also it is worth noting the problem with inclusions. In my main.cpp, I need to add the following includes at the very beginning:

#include <boost/asio.hpp>
#include <windows.h>

This is some kind of well-known problem. If this is not done, then we get a million errors. And what is again strange in sample_code.cpp there is no such problem. This issue is pulled from #include "wallet/monero_wallet_full.h".

Interestingly, if in monero-test/external/monero-cpp/CMakeLists.txt one or only one monero-cpp static lib is linked to the sample_code target, then sample_code compilation will end with the same error: undefined reference to hmac_keccak_hash.

In my opinion, this is very strange behavior. I can't explain it. In essence, the monero-cpp and sample_code targets contain the same set of static libraries in target_link_libraries, with only one difference, an additional unbound is linked to the monero-cpp target, which can also be removed and nothing bad will happen. That is, if in target_link_libraries for the monero-cpp target, register all the static libraries that are in the target_link_libraries for the sample_code target, and link the monero-cpp static library through target_link_libraries to the sample_code target, then this breaks compilation. If, instead, the entire list of static libraries is directly linked to the target sample_code (as is done now), then this does not break anything.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.