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.