vanguard478
vanguard478

Reputation: 129

Using 3rd Party Shared Object Library and header files in CMake

I am trying to use this ZED Open Capture library for using the ZED Mini camera for my project on RaspberryPi. I succesfully installed the library and the shared object file is at /usr/local/lib/libzed_open_capture.so and the include headers are at the location /usr/local/include/zed-open-capture/. To include this library I am adding the following lines to my CMakeLists.txt

find_library(ZED_LIB zed_open_capture) 

include_directories("/usr/local/include/zed-open-capture/")

add_executable(zed_pub src/zed_pub.cpp)

target_link_libraries(zed_pub ${ZED_LIB})

Now when I use this code , it shows this error "‘sl_oc::video’ has not been declared"

#include "videocapture.hpp" //Library Header File
sl_oc::video::VideoCapture cap;
cap.initializeVideo();
const sl_oc::video::Frame frame = cap.getLastFrame();

The github repo of the library is at https://github.com/stereolabs/zed-open-capture

Also I cannot find Find_PKG_name.cmake so I cannot use find_package() option.

Upvotes: 0

Views: 886

Answers (2)

Peter
Peter

Reputation: 14937

videocapture.hpp wraps the definitions you need inside #ifdef VIDEO_MOD_AVAILABLE. It seems likely that this is not defined. The root CMakeLists.txt in the ZED package defaults BUILD_VIDEO to ON, so this was likely all defined for the package build. But as others have pointed out, the package does not persist this information anywhere in the installation. The "right" way for the package to do it would be EITHER to configure/modify the include files at install time to account for the build configuration, probably by generating a "config.hpp" file with the appropriate definitions. OR to include a zed-config.cmake file in the installation, with all the necessary imports and definitions.

Your short-circuit solution should be fine. Just add target_compile_definitions(zed_pub PUBLIC VIDEO_MOD_AVAILABLE). If you want to do it more cleanly for the future, create an IMPORTED target for zed_lib, and set both the include_directories and compile_definitions on that target, so that all users of the library get this defined automatically.

Upvotes: 1

Mizux
Mizux

Reputation: 9301

According to the ZED Open Capture's CMakeLists.txt:

...
# Install rules
set_target_properties(${PROJECT_NAME} PROPERTIES
    PUBLIC_HEADER "${HDR_FULL}"
)
install(TARGETS ${PROJECT_NAME}
    LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zed-open-capture)

ref: https://github.com/stereolabs/zed-open-capture/blob/dfa0aee51ccd2297782230a05ca59e697df496b2/CMakeLists.txt#L142-L148

ZED Open Capture seems to not provide any "CMake config" file...

So you must create your own FindZED.cmake module and/or improve the CMakeLists.txt of this project...

Upvotes: 0

Related Questions