问题:
ubuntu18编译ubuntu16的ros功能包时,pcl 1.8报错:
CMakeFiles/velodyne_imu_gps.dir/src/velodyne_imu_gps.cpp.o:在函数‘chatterCallback(boost::shared_ptr<sensor_msgs::PointCloud2_<std::allocator<void> > const> const&, boost::shared_ptr<sensor_msgs::Imu_<std::allocator<void> > const> const&)’中:
velodyne_imu_gps.cpp:(.text+0x16a8):对‘pcl::visualization::CloudViewer::showCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> const> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’未定义的引用
velodyne_imu_gps.cpp:(.text+0x17ba):对‘pcl::visualization::CloudViewer::showCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> const> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’未定义的引用
velodyne_imu_gps.cpp:(.text+0x18bc):对‘pcl::visualization::CloudViewer::showCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> const> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’未定义的引用
velodyne_imu_gps.cpp:(.text+0x19be):对‘pcl::visualization::CloudViewer::showCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> const> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’未定义的引用
velodyne_imu_gps.cpp:(.text+0x1ac0):对‘pcl::visualization::CloudViewer::showCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> const> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’未定义的引用
CMakeFiles/velodyne_imu_gps.dir/src/velodyne_imu_gps.cpp.o:velodyne_imu_gps.cpp:(.text+0x1bf0): 跟着更多未定义的参考到 pcl::visualization::CloudViewer::showCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> const> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
CMakeFiles/velodyne_imu_gps.dir/src/velodyne_imu_gps.cpp.o:在函数‘__static_initialization_and_destruction_0(int, int)’中:
velodyne_imu_gps.cpp:(.text+0x2b2b):对‘pcl::visualization::CloudViewer::CloudViewer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’未定义的引用
velodyne_imu_gps.cpp:(.text+0x2b58):对‘pcl::visualization::CloudViewer::~CloudViewer()’未定义的引用
collect2: error: ld returned 1 exit status
camera-laser-calibration-master/camLaserCalib/CMakeFiles/velodyne_imu_gps.dir/build.make:319: recipe for target '/home/xx/catkin_ws/devel/lib/cam_laser_calib/velodyne_imu_gps' failed
make[2]: *** [/home/xx/catkin_ws/devel/lib/cam_laser_calib/velodyne_imu_gps] Error 1
CMakeFiles/Makefile2:3694: recipe for target 'camera-laser-calibration-master/camLaserCalib/CMakeFiles/velodyne_imu_gps.dir/all' failed
make[1]: *** [camera-laser-calibration-master/camLaserCalib/CMakeFiles/velodyne_imu_gps.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....
[100%] Built target cam_laser_calib_node
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
解决:
打开cmakelist.txt
在用到CloudViewer::showCloud文件的velodyne_imu_gps.cpp的位置,加上${PCL_LIBRARIES}
如:
add_executable(velodyne_imu_gps src/velodyne_imu_gps.cpp)
target_link_libraries(velodyne_imu_gps ${catkin_LIBRARIES} ${PCL_LIBRARIES})
其他
以下内容非必须的改动
当用到pcl时,在编写cmakelist时:
find_package(PCL REQUIRED)
set(PCL_INCLUDE_DIRS /usr/include/pcl-1.8) #指定pcl1.8路径
add_definitions(${PCL_DEFINITIONS})