Open ghost opened 1 year ago
Maybe I'm using your project in a wrong way? Maybe I'm somehow doing something wrong with CMake scripts?
I would also like to draw attention to the main CMakeLists.txt
. Why is just include_directories
used everywhere? It would be more convenient for developers to use target_include_directories
. If the include paths are connected to a certain target, then when I link this target to my target, I will inherit all the includes, all the paths to them. Otherwise, I have to propagate it myself in my CMakeLists.txt
:
target_include_directories(monero-cpp PUBLIC ${CMAKE_SOURCE_DIR}/external/monero-cpp/src)
target_include_directories(monero-cpp PUBLIC ${CMAKE_SOURCE_DIR}/external/monero-cpp/external/monero-project/contrib/epee/include)
target_include_directories(monero-cpp PUBLIC ${CMAKE_SOURCE_DIR}/external/monero-cpp/external/monero-project/external)
target_include_directories(monero-cpp PUBLIC ${CMAKE_SOURCE_DIR}/external/monero-cpp/external/monero-project/external/easylogging++)
target_include_directories(monero-cpp PUBLIC ${CMAKE_SOURCE_DIR}/external/monero-cpp/external/monero-project/external/rapidjson/include)
target_include_directories(monero-cpp PUBLIC ${CMAKE_SOURCE_DIR}/external/monero-cpp/external/monero-project/src)
target_include_directories(monero-cpp PUBLIC ${CMAKE_SOURCE_DIR}/external/monero-cpp/external/monero-project/src/wallet)
target_include_directories(monero-cpp PUBLIC ${CMAKE_SOURCE_DIR}/external/monero-cpp/external/monero-project/src/wallet/api)
target_include_directories(monero-cpp PUBLIC ${CMAKE_SOURCE_DIR}/external/monero-cpp/external/monero-project/src/hardforks)
target_include_directories(monero-cpp PUBLIC ${CMAKE_SOURCE_DIR}/external/monero-cpp/external/monero-project/src/crypto/crypto_ops_builder/include)
target_include_directories(monero-cpp PUBLIC ${CMAKE_SOURCE_DIR}/external/monero-cpp/external/libsodium/include/sodium)
If this is not done, then with a simple use of the library, when I include #include "wallet/monero_wallet_full.h"
somewhere in the depths of the includes, there is an include that cannot find its way. For example this happened to monero-test/external/monero-cpp/external/libsodium/include/sodium/export.h
. It's just included somewhere as #include "export.h"
.
Have you confirmed that monero-cpp fully builds standalone? It only fails building from an external project?
Have you confirmed that monero-cpp fully builds standalone? It only fails building from an external project?
Yes, monero-cpp
builds completely without problems if you follow the build instructions. The problems start when I try to link it as a static library into my project. Basically I'm doing the same as in sample_code
, but it doesn't work.
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:
Then you need to replace
monero-test/external/monero-cpp/CMakeLists.txt
with themonero-test/patch/CMakeLists.txt
file. This file contains some fixes that allow you to addmonero-cpp
viaadd_subdirectory
to your project.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, thenadd_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
asstatic
and themonero-cpp
library itself can also bestatic
.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:And now I'm getting an error that I can't do anything about and don't understand why it's happening at all:
In fact, I simply copied the contents of
monero-test/external/monero-cpp/test/sample_code.cpp
into mymain.cpp
file. And it is worth noting thatsample_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: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 onemonero-cpp
static lib is linked to thesample_code
target, thensample_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
andsample_code
targets contain the same set of static libraries intarget_link_libraries
, with only one difference, an additionalunbound
is linked to themonero-cpp
target, which can also be removed and nothing bad will happen. That is, if intarget_link_libraries
for themonero-cpp
target, register all the static libraries that are in thetarget_link_libraries
for thesample_code
target, and link themonero-cpp
static library throughtarget_link_libraries
to thesample_code
target, then this breaks compilation. If, instead, the entire list of static libraries is directly linked to the targetsample_code
(as is done now), then this does not break anything.