2014-11-02 130 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})