码迷,mamicode.com
首页 > 其他好文 > 详细

由于未定义的引用,无法获取OpenCV进行编译?

时间:2018-01-02 17:52:44      阅读:3281      评论:0      收藏:0      [点我收藏+]

标签:获取   failed   call   inpu   dev   ons   错误提示   tar   void   

错误提示:

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})

由于未定义的引用,无法获取OpenCV进行编译?

标签:获取   failed   call   inpu   dev   ons   错误提示   tar   void   

原文地址:https://www.cnblogs.com/hello-pdg/p/8178211.html

(0)
(2)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!