I wish to link libraries such as jsoncpp and rapidxml to my C++ code, which will be run on a server machine. The server uses Anaconda virtual environments to remain as clean as possible, so I have to install these packages into an env and direct my code to find them there instead of the usual path. I can link simple externally installed libraries dynamically with CMake but for the life of me I can't figure out how to link the ones installed in Conda envs.
I have tried several variations of:
cmake .. -DCMAKE_PREFIX_PATH=$CONDA_PREFIX
and in the cmake list:
SET(CMAKE_PREFIX_PATH /home/XXX/anaconda3/envs/envname)
and then either having:
target_link_libraries(mycode jsoncpp)
or
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSONCPP jsoncpp)
target_link_libraries(mycode ${JSONCPP_LIBRARIES})
or nothing at all. I haven't installed CMake itself into my Conda env, I have it separately and I only attempt to run make
from the console while being in the active env.
Edit: if I do not use the lines:
target_link_libraries(mycode jsoncpp)
or
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSONCPP jsoncpp)
target_link_libraries(mycode ${JSONCPP_LIBRARIES})
Then CMake throws me a long winded error full of
undefined reference to `Json::Value::~Value()'
If I do use one of those options, then when I want to execute the binary on another machine, inside a Conda environment with jsoncpp installed, I get this error:
error while loading shared libraries: libjsoncpp.so.1: cannot open shared object file: No such file or directory
Because of this, I assume CMake linked the globally installed jsoncpp somehow, not the Conda one.