Reputation: 91
I have been losing my head over this for some time now. So I need to use the opencv in a ros melodic package built by the catkin on the Ubuntu 18.04. The idea is to make a package which is actually just a library and this library using all the regular ros packages (image_transport, cv_bridge, roscpp, rospy, std_msgs, genmsg, tf, actionlib_msgs, actionlib ).
Just to let you know, I have 2 opencv installed, the openCV 3.2 in the usr/share
and the openCV 4.3 in the usr/local/share
, that is why I have specifically set the openCV_DIR to point to the 3.2 version.
I have tried to add message
to the CMakeList.txt to print out the opencv_version, opencv_include_dir and opencv_libs and the version is 3.2.0
, include_dirs is /usr/include;/usr/include/opencv
and libs are opencv_calib3d;opencv_core;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab;opencv_viz;opencv_aruco;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_datasets;opencv_dpm;opencv_face;opencv_freetype;opencv_fuzzy;opencv_hdf;opencv_line_descriptor;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_reg;opencv_rgbd;opencv_saliency;opencv_stereo;opencv_structured_light;opencv_surface_matching;opencv_text;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto
in my pkg_library
CMakeList.txt
I have this:
cmake_minimum_required(VERSION 2.8.3)
project(pkg_libraries)
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
set( OpenCV_DIR "/usr/share/OpenCV/" )
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(
catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
genmsg
tf
actionlib_msgs
actionlib
sensor_msgs
cv_bridge
image_transport
message_generation
)
find_package(
OpenCV REQUIRED
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES pkg_libraries
CATKIN_DEPENDS roscpp rospy std_msgs tf actionlib actionlib_msgs cv_bridge
)
include_directories(
include
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
add_library(${PROJECT_NAME}
src/imageSaver.cpp
)
target_link_libraries( ${PROJECT_NAME} ${catkin_LIBRARIES} ${OpenCV_LIBS} )
install(
TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)
install(
DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
)
the compilation of the pkg_libraries
with the catkin_build
looks just fine, but later when I try to do catkin_build
in the another package which includes the pkg_libraries
, it fails with the error:
libpkg_libraries.so: undefined reference to `cv::imwrite(std::__cxx11::basic_string, std::allocator > const&, cv::_InputArray const&, std::vector > const&)'
Which I would say looks like the linker error, because I have used the cv::imwrite
only in the pkg_libraries
. and the package which reports the error includes only the pkg_libraries
. So the pkg_libraries
but it is obviously not linked properly, but it is built without errors.
What am I missing here?
Thanks
Upvotes: 1
Views: 1054
Reputation: 91
the problem was because of the pkg_libraries
is built like a shared library in which I have had another .cpp
and .h
which were using different openCV
versions (default opencv 3.2) and I think the problem happened because by loading the libpkg_libraries.so
I have made a conflict between openCV
version.
Anyway, now I have made separate libraries and it works as it suppose to work.
Thanks
Upvotes: 1