Library with different OpenCV version crashes
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)