ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

Compiling with Cmake and PCL

asked 2014-03-30 17:36:19 -0600

Maya gravatar image

updated 2014-03-30 18:46:13 -0600

Hellow everyone,

I have a problem with compiling my code and I can't seem to find the solution anywhere. I'm using PCL. My main is in a one file named main.cpp. The code inside is irrelevant. The thing is in order to use the fromROSMsg() pcl_ros function I need to declare it somewhere in the main file. Like for example I have a function callback() for now that is used absolutely nowhere in the code later on like this :

void callback(){
  const sensor_msgs::PointCloud2ConstPtr& cloudy;
  pcl::PointCloud<pcl::PointXYZRGBA> cloud;
  pcl::fromROSMsg(*cloudy, cloud);  
}

And this function is absolutely of no use later on since my callback function is actually a class function somewhere else using fromROSMsg by herself. but if I don't include this function somewhere in the main file here is the result of CMake :

/home/ros/catkin_ws/devel/lib/lib3Dmain.so: undefined reference to 'pcl::console::print(pcl::console::VERBOSITY_LEVEL, char const*, ...)'
collect2: ld a retourné 1 code d'état d'exécution
make[2]: *** [/home/ros/catkin_ws/devel/lib/open_tld_3d/opentld_3D] Erreur 1
make[1]: *** [open_tld_3d/CMakeFiles/opentld_3D.dir/all] Erreur 2

I tried linking manually PCL in themakefile as explain Here but it didn't help.

Thanks a lot for any help.

Here is the CMakeLists.txt :

cmake_minimum_required(VERSION 2.8.3)
project(this_project)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
cv_bridge
geometry_msgs
pcl
pcl_ros
roscpp
rospy
sensor_msgs
std_msgs
)

find_package(PCL REQUIRED)

find_package(OpenCV REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})

link_directories(${PCL_LIBRARY_DIRS})

include_directories(${OpenCV_INCLUDE_DIRS}
include/this_project)

include_directories(
src/opentld
src/opentld/main
src/libopentld/imacq
src/libopentld/mftracker
src/libopentld/tld
src/libopentld/tld/detector
src/libopentld/tld/detector/cuda
src/3rdparty/cvblobs
src/3rdparty/libconfig)

include_directories(src/libopentld/imacq
src/libopentld/mftracker
src/libopentld/tld
src/libopentld/tld/detector
src/libopentld/tld/detector/cuda
src/libopentld/tld/detector/cuda/npp
${CUDA_INCLUDE_DIRS})


## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)


## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

 ###################################
## catkin specific configuration ##
 ###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
 INCLUDE_DIRS include
 LIBRARIES open_tld_3d
 CATKIN_DEPENDS geometry_msgs roscpp rospy std_msgs pcl_ros pcl
 DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
   ${catkin_INCLUDE_DIRS}
)

## Declare a cpp library
add_library(3dlib
include/open_tld_3d/handler3D.cpp
include/open_tld_3d/handler3D.hpp)

add_library(3Dcvblobs
src/3rdparty/cvblobs/blob.cpp
src/3rdparty/cvblobs/BlobContour.cpp
src/3rdparty/cvblobs/BlobOperators.cpp
src/3rdparty/cvblobs/BlobProperties.cpp
src ...
(more)
edit retag flag offensive close merge delete

Comments

This looks like a linking problem. Can you include your CMakeLists.txt in your post?

ahendrix gravatar image ahendrix  ( 2014-03-30 18:36:41 -0600 )edit

Sure thing.

Maya gravatar image Maya  ( 2014-03-30 18:41:05 -0600 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2014-03-30 19:04:32 -0600

ahendrix gravatar image

It looks like you should add ${PCL_LIBRARIES} when you link 3Dmain.

edit flag offensive delete link more

Comments

That worked. But why was CMake able to find it if I put the function in the project file ? I just can't understand why...

Maya gravatar image Maya  ( 2014-03-30 19:22:01 -0600 )edit

The add_library controls which C++ files are compiled into your object file, and target_link_libraries controls which libraries are linked with your object file to produce your library.

ahendrix gravatar image ahendrix  ( 2014-03-30 20:56:17 -0600 )edit

find_package(PCL) sets a number of environment variables, including PCL_INCLUDE_DIRS and PCL_LIBRARIES.

ahendrix gravatar image ahendrix  ( 2014-03-30 20:57:17 -0600 )edit

Ha ok ! thanks a lot !

Maya gravatar image Maya  ( 2014-03-30 21:00:42 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-03-30 17:36:19 -0600

Seen: 6,410 times

Last updated: Mar 30 '14