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.

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
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.

  • Is it possible to serialize the memory held by A* pointer in C into an unsigned char array? – Joel D Sep 13 '17 at 13:30
  • It depends on the object. Some objects can be serialized. They have a serialize function. – user36303 Sep 13 '17 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.