2014-11-02 318 views
2

下面的代码:无法链接到pcl库。

#include <ros/ros.h> 
#include <pcl_ros/point_cloud.h> 
#include <pcl/point_types.h> 
#include <boost/foreach.hpp> 

typedef pcl::PointCloud<pcl::PointXYZ> PointCloud; 
void callback(const PointCloud::ConstPtr& msg) 
{ 
    printf ("Cloud: width = %d, height = %d\n", msg->width, msg->height); 
    BOOST_FOREACH (const pcl::PointXYZ& pt, msg->points) 
    printf ("\t(%f, %f, %f)\n", pt.x, pt.y, pt.z); 
} 

int main(int argc, char** argv) 
{ 
    ros::init(argc, argv, "sub_pcl"); 
    ros::NodeHandle nh; 
    ros::Subscriber sub = nh.subscribe<PointCloud>("points2", 1, callback); 
    ros::spin(); 
} 

这是从here

我的CMake采取了默认的例子:

cmake_minimum_required(VERSION 2.6 FATAL_ERROR) 
find_package(PCL 1.3 REQUIRED COMPONENTS common io) 
include_directories(${PCL_INCLUDE_DIRS}) 
link_directories(${PCL_LIBRARY_DIRS}) 
add_definitions(${PCL_DEFINITIONS}) 
target_link_libraries(${PROJECT_NAME} ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES}) 

这是推荐在PCL官方的确切配置website

我仍然得到以下链接错误:

CMakeFiles/apsp_manifold.dir/src/apsp_manifold.cpp.o: In function `void pcl::detail::FieldMapper<pcl::PointXYZ>::operator()<pcl::fields::z>()': 
/usr/include/pcl-1.7/pcl/conversions.h:106: undefined reference to `pcl::console::print(pcl::console::VERBOSITY_LEVEL, char const*, ...)' 
CMakeFiles/apsp_manifold.dir/src/apsp_manifold.cpp.o: In function `void pcl::detail::FieldMapper<pcl::PointXYZ>::operator()<pcl::fields::y>()': 
/usr/include/pcl-1.7/pcl/conversions.h:106: undefined reference to `pcl::console::print(pcl::console::VERBOSITY_LEVEL, char const*, ...)' 
CMakeFiles/apsp_manifold.dir/src/apsp_manifold.cpp.o: In function `void pcl::detail::FieldMapper<pcl::PointXYZ>::operator()<pcl::fields::x>()': 
/usr/include/pcl-1.7/pcl/conversions.h:106: undefined reference to `pcl::console::print(pcl::console::VERBOSITY_LEVEL, char const*, ...)' 

我有什么上述错误,我该如何删除它?

+0

尝试'make VERBOSE = 1'并检查编译器选项是否存在适当的库......它看起来像某个库已经混乱。 – zaufi 2014-11-03 04:57:17

回答

0

问题是如下:从教程中的代码是旧的,上一次的页面被修改 - 2011-08-09。

我能找到的唯一合理的解释是,显然PCL库并没有从头文件中去掉与旧版本相关的代码,而是只删除了与那些函数调用相关的符号文件,所以会发生什么:解析会成功(因为函数声明在那里),而链接将失败,因为没有任何关联。 This是我最终使用的教程。

1

只是猜测,但也许问题是并非所有必需的组件都包括在内。

这是我的链接PCL:

find_package(PCL REQUIRED) 
include_directories(... ${PCL_INCLUDE_DIRS}) 
... 
target_link_libraries(... ${PCL_LIBRARIES})