错误提示:
CMakeFiles/my_subscriber.dir/src/my_subscriber.cpp.o:在函数‘imageCallback(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)’中:
my_subscriber.cpp:(.text+0xb0):对‘cv::imshow(cv::String const&, cv::_InputArray const&)’未定义的引用
CMakeFiles/my_subscriber.dir/src/my_subscriber.cpp.o:在函数‘main’中:
my_subscriber.cpp:(.text+0x405):对‘cv::namedWindow(cv::String const&, int)’未定义的引用
my_subscriber.cpp:(.text+0x419):对‘cv::startWindowThread()’未定义的引用
my_subscriber.cpp:(.text+0x66b):对‘cv::destroyWindow(cv::String const&)’未定义的引用
collect2: error: ld returned 1 exit status
my_image_transport/CMakeFiles/my_subscriber.dir/build.make:128: recipe for target ‘/home/pdg/catkin_ws/devel/lib/my_image_transport/my_subscriber‘ failed
make[2]: *** [/home/pdg/catkin_ws/devel/lib/my_image_transport/my_subscriber] Error 1
CMakeFiles/Makefile2:1706: recipe for target ‘my_image_transport/CMakeFiles/my_subscriber.dir/all‘ failed
make[1]: *** [my_image_transport/CMakeFiles/my_subscriber.dir/all] Error 2
Makefile:138: recipe for target ‘all‘ failed
make: *** [all] Error 2
解决方法:
CMakeLists.txt中要有target_link_libraries(my_subscriber ${catkin_LIBRARIES} ${OpenCV_LIBS})
完整CMakeLists.txt文件如下:
cmake_minimum_required(VERSION 2.8.3)
project(my_image_transport)
find_package(catkin REQUIRED COMPONENTS
OpenCV
cv_bridge
image_transport
)
include_directories(
include
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
add_executable(my_subscriber src/my_subscriber.cpp)
target_link_libraries(my_subscriber ${catkin_LIBRARIES} ${OpenCV_LIBS})