【问题标题】:Can not link to pcl library.无法链接到 pcl 库。
【发布时间】:2014-11-20 23:50:15
【问题描述】:

以下代码:

#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*, ...)'

上面描述的错误是怎么回事?如何消除它?

【问题讨论】:

标签: linker cmake point-cloud-library ros


【解决方案1】:

只是一个猜测,但问题可能在于并未包含所有必需的组件。

这就是我链接 PCL 的方式:

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

【讨论】:

    【解决方案2】:

    问题如下:教程中的代码很旧,最后一次修改页面 - 2011-08-09。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-23
      • 2017-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多