5

I am looking to build an offline wallet for Monero. However, most of my tooling is in Perl and C. If Monero was written in C, I could just call the C functions from my Perl modules. I think it is possible to call C++ functions from Perl relatively painlessly, but to do that I need to know how to access the functions in the Monero code base. Would someone be able to point out how to install Monero as a library instead of just the binary? Or does the docker install also include installing a library? It looks like it comes down to getting monero_headers.h to get imported into a C file and calling it from my Perl code.

user36303
  • 34,928
  • 2
  • 58
  • 123
Joel D
  • 53
  • 3

2 Answers2

7

Monero can be built using the DBUILD_SHARED_LIBS flag that triggers building the optional shared libraries.

apt-get install git cmake build-essential libssl-dev pkg-config libboost-all-dev
git clone https://github.com/monero-project/monero.git
cd monero
git checkout tags/v0.11.0.0 -b release-v0.11.0.0
cmake -DBUILD_SHARED_LIBS=1 .
make
Coin Foundry
  • 348
  • 2
  • 7
3

You'd need to write a layer in C++ which would export C linkage functions (ie, extern "C" { ... }) while using C++ objects in their implementation. They'd essentially do this kind of thing:

Original:

class A { A(); void work(); };

C layer:

extern "C" { A *A_create() { return new A(); } void A_destroy(A *a) { delete a; } void A_work(A *a) { a->work(); } }

Then you could call the A_create/A_work/A_destroy API, which would be undecorated and usable with C ABI.

user36303
  • 34,928
  • 2
  • 58
  • 123