Ask Your Question
4

Can not link to pcl library.

asked 2014-11-02 15:39:32 -0500

abarbarosie gravatar image

The following code:

#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();
}

Which is a default tutorial on how to use PCL in ros.

My 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})

Which is the exact configuration recommended on the pcl official website

I still get the following linking error:

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

What do I have the above described error and how can I remove it?

edit retag flag offensive close merge delete

Comments

1

If you're having trouble linking against PCL, you should probably ask on their mailing list rather than here. This tutorial looks VERY old; I suspect it isn't entirely compatible with the more recent versions of PCL.

ahendrix gravatar image ahendrix  ( 2014-11-02 17:49:44 -0500 )edit
1

It would also be useful to link to the PCL documentation that you're using when you report this: http://pointclouds.org/documentation/...

ahendrix gravatar image ahendrix  ( 2014-11-02 17:50:06 -0500 )edit

3 Answers

Sort by » oldest newest most voted
1

answered 2014-11-03 02:49:18 -0500

abarbarosie gravatar image

updated 2014-11-03 21:22:12 -0500

Thanks to @ahendrix pointing out that the tutorial is old. I found this tutorial page which gave me enough insight and the linker was not complaining.

In relation to my question, apparently the issue was incompatibility of the code which is old with the library which is new. The headers are there but the object files in the library are missing.

edit flag offensive delete link more
2

answered 2017-08-08 05:22:23 -0500

张京林 gravatar image

target_link_libraries( ... ${PCL_LIBRARIES})

add${PCL_LIBRARIES} may help

edit flag offensive delete link more

Comments

Thanks a lot, it works.

I am using: Ubuntu 18.04 LTS, ROS Kinetic

Attaching my working CMakeLists.txt for reference.

cmake_minimum_required(VERSION 2.8.3)
project(enter_your_package_name)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  sensor_msgs
)

find_package(PCL)

catkin_package(
)

include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable(file_name src/file_name.cpp)

add_dependencies(file_name ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(file_name
  ${catkin_LIBRARIES}
  ${PCL_LIBRARIES}
)
askkvn gravatar image askkvn  ( 2020-04-30 08:22:55 -0500 )edit
0

answered 2014-11-02 16:12:43 -0500

paulbovbel gravatar image

updated 2014-11-03 07:27:41 -0500

You should use the ROS tutorials for writing your CMakeLists.txt. The perception_pcl tutorials need to be updated (pcl is now a system dependency), and the hydro migration guide has some useful info. You should include the following:

find_package(catkin REQUIRED COMPONENTS
  ...
)
find_package(PCL REQUIRED COMPONENTS ...)

include_directories(include ${catkin_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS})    

catkin_package(
  ...
  DEPENDS
    PCL
)

add_executable(<node> src/<node>.cpp)
target_link_libraries(<node> ${catkin_LIBRARIES} ${PCL_LIBRARIES})
edit flag offensive delete link more

Comments

I think the include_directories(..) statement only makes sense after the find_package(PCL ..). As it is now, it will add an unset (empty) variable to the include path.

gvdhoorn gravatar image gvdhoorn  ( 2014-11-03 01:37:19 -0500 )edit

Thanks, edited. i didn't read the errors above carefully - cmake wasn't the issue anyway. I'll leave this for reference until the ROS/PCL tutorials get updated.

paulbovbel gravatar image paulbovbel  ( 2014-11-03 07:27:14 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2014-11-02 15:39:32 -0500

Seen: 4,809 times

Last updated: Aug 08 '17