I am trying to include this C++ library with CMake. As I understood, the file that I need to include is located at lib/libbinacpp/lib/libbinacpp.so
(relative to the library root folder).
So, I created a new folder, with two subfolders
src
, which only contains one file:src/main.cpp
(a simple Hello, World)lib
, which contains a folderbinacpp
, the result of cloning the library
On the top level, I have my CMakeLists.txt
. First, I tried to write the following:
cmake_minimum_required(VERSION 3.20)
project(RebalancerBot)
set(CMAKE_CXX_STANDARD 20)
#Include binacpp
add_library(binacpp SHARED IMPORTED)
set_target_properties(binacpp PROPERTIES IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/lib/binacpp/lib/libbinacpp/lib/libbinacpp.so)
add_executable(RebalancerBot src/main.cpp)
#Link everything after adding the executable
target_link_libraries(RebalancerBot PRIVATE binacpp)
Which resulted in the error
make[3]: *** No rule to make target 'lib/binacpp/lib/libbinacpp/lib/libbinacpp.so', needed by 'RebalancerBot'. Stop.
To my surprise, I got a different error after replacing ${CMAKE_BINARY_DIR}
with the actual root path of my folder (i.e /home/actual_path/
). I found this surprising since I thought that ${CMAKE_BINARY_DIR}$
should exactly be the path to the root CMakeLists.txt
file. Anyway, after the replacement, I got the following new errors:
/usr/bin/ld: warning: libcrypto.so.1.0.0, needed by ../lib/binacpp/lib/libbinacpp/lib/libbinacpp.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libwebsockets.so.11, needed by ../lib/binacpp/lib/libbinacpp/lib/libbinacpp.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: ../lib/binacpp/lib/libbinacpp/lib/libbinacpp.so: undefined reference to `lws_client_connect_via_info'
/usr/bin/ld: ../lib/binacpp/lib/libbinacpp/lib/libbinacpp.so: undefined reference to `lws_callback_on_writable'
... (the list goes on)
If I understand correctly, these errors are due to the dependencies of libbinacpp.so
. How can fix them?
PS: It should be noted that, if I cd
into lib/binacpp/src
and make
inside of this directory, everything runs without errors.
EDIT: Thanks to @AlanBirtles comment, I found that the error with CMAKE_BINARY_DIR
was due to the fact that it unfolds to the directory I run cmake
in. What I needed was CMAKE_SOURCE_DIR
: the directory containing my cmake
file.