Background:
I'm compiling a shared C library in a separate project and need to link against it with CMake.
I've used a C based neural network implementation called darknet to train a custom object detector.
Actually darknet is a standalone C executable. But I need to integrate the detector into a larger C++ codebase. I already found a small wrapper. Now I would like to convert the wrapper code into a CMake project, compile darknet into a shared library and link against it.
- I've compiled this to a shared library with the compiler flags
-fPIC
and-shared
. - The output was called
darknet
, I renamed it todarknet.so
and copied it to/usr/lib/
sudo ldconfig
Question:
This is my CMakeLists.txt
. As you can see, I'm linking against the darknet library. At compile time, there is an error, the library isn't found.
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
project(wrapper)
add_definitions(-std=c++14)
find_package(OpenCV 3.2.0 EXACT REQUIRED)
include_directories(
${OpenCV_INCLUDE_DIRS}
example
wrapper
darknet_src
)
SET(SOURCES
example/main.cpp
wrapper/darknet.cpp
wrapper/darknet.h
wrapper/darknet_detector.c
wrapper/darknet_detector.h)
add_executable(wrapper ${SOURCES})
target_link_libraries(wrapper darknet ${OpenCV_LIBS})