monero-cpp icon indicating copy to clipboard operation
monero-cpp copied to clipboard

How to link and compile sample_code with the shared library ?

Open ianniculescu opened this issue 2 years ago • 2 comments

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)

ianniculescu avatar Aug 03 '22 20:08 ianniculescu

If the build is succeeding, running ./bin/build_libmonero_cpp.sh will first build monero-project, and then build the shared library in monero-cpp/build, which can be used in another project. For example, monero-java imports the shared library for JNI bindings.

Running ./bin/build_libmonero_cpp.sh will also create monero-cpp/build/sample_code which can be run with ./sample_code (will require customizing the config in sample_code.cpp for your environment).

If using monero-cpp in your own project, I'd recommend either importing the shared library like monero-java, or setting up a CMakeLists.txt file which directly imports monero-cpp's source files. For example, monero-javascript uses a CMakeLists.txt file which links to monero-cpp's main source files, like monero_wallet_full.cpp.

libwallet_merged.a has actually been removed and is no longer built in monero-project. I'm working on a new release of this library, expected within a week, which will build with the latest monero-project to fix this, so best to wait if you're currently having build problems.

woodser avatar Aug 04 '22 13:08 woodser

A new version of this library is released, v0.7.2, which updates the dependencies and completely removes libwallet_merged.a. Please try the new version and let me know if you continue to have problems.

woodser avatar Aug 07 '22 13:08 woodser

This issue should be fixed in the latest release, which no longer uses libwallet_merged.a at all.

Please reopen if there are still problems.

woodser avatar Jan 11 '23 14:01 woodser