[ROS调用cv_bridge]undefined reference to `cv_bridge::toCvCopy(boost::shared_ptr<sensor_msgs::Image_

用ROS调用cv_bridge的时候,报了个错,如下:

undefined reference to `cv_bridge::toCvCopy(boost::shared_ptr const> const&, std::__cxx11::basic_string const&)’

意思就是我用的这个cv_bridge::toCvCopy函数没有定义,虽然我在开头已经include了对应的库,如:

#include 
#include 
#include 
#include 
#include 
#include 
#include

但是其实还不行,需要在CMakeLists.txt里面也加入对应的cv_bridge package去编译才行:

...
find_package(Eigen3 REQUIRED)
find_package(PCL 1.8 REQUIRED)
find_package(OpenCV REQUIRED)

find_package(catkin REQUIRED COMPONENTS 
nav_msgs 
roscpp 
rospy 
serial 
tf 
std_msgs 
std_srvs 
actionlib
actionlib_msgs
message_generation
geometry_msgs
pcl_conversions
pcl_ros 
cv_bridge
)

...

add_executable(Frustum src/Frustum.cpp)
target_link_libraries(Frustum ${PCL_LIBRARIES} ${OpenCV_LIBRARIES} ${catkin_LIBRARIES} ${EIGEN3_LIBS})


所以在find_package里面加入cv_bridge就可以了,有的blog 说需要在xml文件了也加,我现在没加好像也没有什么问题。

你可能感兴趣的:(ROS,learning,opencv,ROS)