ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Library with different OpenCV version crashes

asked 2020-02-17 11:04:26 -0500

fehlfarbe gravatar image

Hi,

I'm writing a library (dps_calib) without ROS dependencies that depends on OpenCV 4.2 with aruco and camera calibration modules. My test program (print_boards) takes my library to generate, save and load some YAML files with markerboard descriptions which runs without problems. But when I use the library in a ROS node with cv_bridge (for Images/Mat converting) it always crashes with segfaults when I try to open a YAML file. I assume the problem is that cv_bridge links to libopencv_core.so.3.2 and the library links to 4.2 because I get similar effects when I add ${catkin_LIBRARIES} to my test program. When I link my library to OpenCV 3.2 I don't have any problems.

Is this some problem with my CMakeLists.txt or is it just impossible to use multiple libraries that depend on different OpenCV versions?

My system: Linux Mint 19.1 Tessa ROS Melodic

CMakeLists.txt snippet:

find_package(catkin REQUIRED COMPONENTS
    roscpp
    rospy
    std_msgs
    sensor_msgs
    geometry_msgs
    message_generation
    genmsg
    actionlib_msgs
    actionlib
    image_transport
    cv_bridge
    tf
)

find_package(OpenCV 4 REQUIRED)

## Declare a C++ library
add_library(dps_calib
    src/dps_calib/DPSCalib.cpp
)

target_link_libraries(dps_calib
        opencv_core
        opencv_imgproc
        opencv_aruco
        )

## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## position calibration
add_executable(calibration src/calibration_node.cpp src/DPSCalibrationNode.cpp)
add_dependencies(calibration dps_calib ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(calibration
        dps_calib
        ${catkin_LIBRARIES}
)

## print boards and so on
add_executable(print_boards src/print_boards.cpp)
add_dependencies(print_boards dps_calib ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS} )
target_link_libraries(print_boards
#        ${catkin_LIBRARIES}
        dps_calib
        opencv_highgui
        opencv_core
)

ldd dps_calib/calibration | grep opencv_:

libopencv_core.so.3.2 => /usr/lib/x86_64-linux-gnu/libopencv_core.so.3.2 (0x00007ff5162d6000)
libopencv_core.so.4.2 => /usr/local/lib/libopencv_core.so.4.2 (0x00007ff513b3b000)
libopencv_aruco.so.4.2 => /usr/local/lib/libopencv_aruco.so.4.2 (0x00007ff512afa000)
libopencv_imgcodecs.so.4.2 => /usr/local/lib/libopencv_imgcodecs.so.4.2 (0x00007ff511467000)
libopencv_imgproc.so.4.2 => /usr/local/lib/libopencv_imgproc.so.4.2 (0x00007ff50f4cc000)
libopencv_calib3d.so.4.2 => /usr/local/lib/libopencv_calib3d.so.4.2 (0x00007ff50d9cd000)
libopencv_features2d.so.4.2 => /usr/local/lib/libopencv_features2d.so.4.2 (0x00007ff50b4ff000)
libopencv_flann.so.4.2 => /usr/local/lib/libopencv_flann.so.4.2 (0x00007ff50b253000)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-02-17 11:10:14 -0500

gvdhoorn gravatar image

is it just impossible to use multiple libraries that depend on different OpenCV versions?

I would hazard a guess and answer "yes" here.

This is likely a case of ABI incompatibility, which is very easy to achieve when linking to different versions of the same library within a single binary. Crashes (probably SEGFAULTs) typically follow.

Note this is not a "ROS problem": you'll have this problem with or without ROS. It's a general problem when working with compiled languages (which support dynamic libraries).

edit flag offensive delete link more

Question Tools

Stats

Asked: 2020-02-17 11:04:26 -0500

Seen: 385 times

Last updated: Feb 17 '20