# Compiling with Cmake and PCL

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 ... edit retag close merge delete ## Comments This looks like a linking problem. Can you include your CMakeLists.txt in your post? ( 2014-03-30 18:36:41 -0600 )edit Sure thing. ( 2014-03-30 18:41:05 -0600 )edit ## 1 Answer Sort by » oldest newest most voted It looks like you should add${PCL_LIBRARIES} when you link 3Dmain.

more

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...

( 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.

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

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

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

Ha ok ! thanks a lot !

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