OpenCV-ROS catkin_make error

asked 2020-10-12 08:06:22 -0500

RGCesar94 gravatar image

Hi, I'm working with OpenCV and ROS in Ubuntu 18.04.5 Melodic, using the cv_bridge C++ tutorial (

I followed different guides to create the package and the specific node for the image_converter.cpp file (similar to the one described in the guide, basically this steps:

when I tried to compile the workspace I got the following error:

CMakeFiles/image_converter.dir/src/image_converter.cpp.o: In function ImageConverter::ImageConverter()': image_converter.cpp:(.text._ZN14ImageConverterC2Ev[_ZN14ImageConverterC5Ev]+0x4bc): undefined reference to cv::namedWindow(cv::String const&, int)' CMakeFiles/image_converter.dir/src/image_converter.cpp.o: In function ImageConverter::~ImageConverter()': image_converter.cpp:(.text._ZN14ImageConverterD2Ev[_ZN14ImageConverterD5Ev]+0x36): undefined reference to cv::destroyWindow(cv::String const&)' CMakeFiles/image_converter.dir/src/image_converter.cpp.o: In function `ImageConverter::imageCb(boost::shared_ptr<sensor_msgs::image_<std::allocator<void>

const> const&)': image_converter.cpp:(.text._ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE[_ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE]+0x1d9): undefined reference to cv::imshow(cv::String const&, cv::_InputArray const&)' image_converter.cpp:(.text._ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE[_ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE]+0x1fe): undefined reference to cv::waitKey(int)' collect2: error: ld returned 1 exit status opencv_cpp/CMakeFiles/image_converter.dir/build.make:126: recipe for target '/home/cesarrg/OpenCVtuto_ws/devel/lib/opencv_cpp/image_converter' failed make[2]: * [/home/cesarrg/OpenCVtuto_ws/devel/lib/opencv_cpp/image_converter] Error 1 CMakeFiles/Makefile2:1264: recipe for target 'opencv_cpp/CMakeFiles/image_converter.dir/all' failed make[1]: [opencv_cpp/CMakeFiles/image_converter.dir/all] Error 2 Makefile:140: recipe for target 'all' failed make: ** [all] Error 2 Invoking "make -j8 -l8" failed

I've been looking in different forums and trying to find a solution but without luck.

May anyone can help me to solve it? Thanks in advance


edit retag flag offensive close merge delete


It appears to be failing to link to the OpenCV library.

First, do you have OpenCV installed? For example, the following command

$ sudo apt-get install libopencv-dev python3-opencv

If installed, does the CMakeLists.txt mention the use of OpenCV? You will need to include the following

find_package(OpenCV REQUIRED)
miura gravatar image miura  ( 2020-10-12 09:05:37 -0500 )edit

Perfect thanks, I did have OpenCV installed but indeed I forgot to add the other commands to the CMakeList.txt, thanks.

RGCesar94 gravatar image RGCesar94  ( 2020-10-15 03:40:19 -0500 )edit