0
$\begingroup$

Rosanswers logo

Hi, I am trying to run the full example in the cv_bridge tutorial at http://wiki.ros.org/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages . I am having serious trouble compiling the node. I get the following undefined reference errors for opencv functions as follows:

CMakeFiles/c_test_node.dir/src/c_test_node.cpp.o: In function `ImageConverter::ImageConverter()':
c_test_node.cpp:(.text._ZN14ImageConverterC2Ev[_ZN14ImageConverterC5Ev]+0x3f1): undefined reference to `cv::namedWindow(cv::String const&, int)'
CMakeFiles/c_test_node.dir/src/c_test_node.cpp.o: In function `ImageConverter::imageCb(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)':
c_test_node.cpp:(.text._ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE[_ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE]+0x1bd): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
c_test_node.cpp:(.text._ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE[_ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE]+0x1e2): undefined reference to `cv::waitKey(int)'
collect2: error: ld returned 1 exit status
c_test/CMakeFiles/c_test_node.dir/build.make:132: recipe for target '/home/auv/c_test_ws/devel/lib/c_test/c_test_node' failed
make[2]: *** [/home/auv/c_test_ws/devel/lib/c_test/c_test_node] Error 1
CMakeFiles/Makefile2:1813: recipe for target 'c_test/CMakeFiles/c_test_node.dir/all' failed
make[1]: *** [c_test/CMakeFiles/c_test_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

I have tried updating the include lines from:

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

to

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

However, I am not having luck with that either.

Any help or insight on this is very appreciated.

As per @Maarten 's suggestion, I am including my CMakeLists.txt here:

cmake_minimum_required(VERSION 2.8.3)
project(c_test)
find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  image_transport
  roscpp
  sensor_msgs
  std_msgs
  tf
)
catkin_package(
CATKIN_DEPENDS cv_bridge image_transport roscpp sensor_msgs std_msgs
)
include_directories(
  ${catkin_INCLUDE_DIRS}
)
add_executable(c_test_node src/c_test_node.cpp)
target_link_libraries(c_test_node ${OpenCV_LIBS} ${catkin_LIBRARIES})

Originally posted by vik748 on ROS Answers with karma: 151 on 2018-03-21

Post score: 4


Original comments

Comment by gvdhoorn on 2018-03-21:
Pedantic (but important): it's actually compiling fine, it's during linking that you get errors. Changing the includes will not affect that.

Comment by Maarten on 2018-03-21:
If you can't get it to work, please post your CMakeLists.txt too.

Comment by vik748 on 2018-03-21:
@Maarten thanks for the suggestion. Unfortunately adding the flag doesn't seemed to have helped. I will updated the question to add my CMakeLists.txt

Comment by Maarten on 2018-03-21:
I also have

## OpenCV
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

in my CMakeLists.txt. I think the ${OpenCV_LIBS} variable is defined by this find_package script.

Comment by vik748 on 2018-03-21:
@Maarten I was doing find_package(OpenCV REQUIRED), but had commented it out. Now that in combination with target_link_libraries seems to have done the trick. Thanks very much for your help.

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

My nodes using OpenCV have ${OpenCV_LIBS} in their target_link_libraries definition. I don't know what other OpenCV functions you are using, but since you get link errors on OpenCV symbols, it is worth checking whether you actually link the OpenCV library in your application.


Originally posted by Maarten with karma: 206 on 2018-03-21

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

As per @Maarten 's suggestion, updating the CMakeLists.txt as follows, seems to have solved the issue

cmake_minimum_required(VERSION 2.8.3)
project(c_test)
find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  image_transport
  roscpp
  sensor_msgs
  std_msgs
  tf
)
find_package(OpenCV REQUIRED)
catkin_package(
CATKIN_DEPENDS cv_bridge image_transport roscpp sensor_msgs std_msgs
)
include_directories(
  ${catkin_INCLUDE_DIRS}
)
add_executable(c_test_node src/c_test_node.cpp)
target_link_libraries(c_test_node ${OpenCV_LIBS} ${catkin_LIBRARIES})

Originally posted by vik748 with karma: 151 on 2018-03-21

This answer was NOT ACCEPTED on the original site

Post score: 5


Original comments

Comment by Jim Chaik on 2018-11-02:
could you also post your package.xml file? I am having some trouble with the tutorial and it would help me see if I have made any mistakes in my package.xml Thank you

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.