Unable to link ros::package::getPath
I'm trying to do the same as this example : https://answers.ros.org/question/3952...
The function is documented here : http://docs.ros.org/en/jade/api/rosli...
I created a minimum reproductible example of my problem, which I tested both on Kinetic and Noetic :
test.cpp :
#include <iostream>
#include <ros/package.h>
int main(int argc, char **argv)
{
std::cout << "Hello, world!" << std::endl;
std::string testString = ros::package::getPath("testPath");
std::cout << "Package path is " << testString << std::endl;
}
Package.xml :
<?xml version="1.0"?>
<package format="2">
<name>testPath</name>
<version>0.0.0</version>
<description>The testPath package</description>
<maintainer email="victor@todo.todo">victor</maintainer>
<license>TODO</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>roslib</build_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>roslib</build_export_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>roslib</exec_depend>
<export>
<!-- Other tools can request additional information be placed here -->
</export>
</package>
CmakeList :
cmake_minimum_required(VERSION 3.0.2)
project(testPath)
find_package(catkin REQUIRED COMPONENTS
roscpp
roslib
)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES testPath
# CATKIN_DEPENDS roscpp roslib
# DEPENDS system_lib
)
include_directories(
# include
${catkin_INCLUDE_DIRS}
)
## Declare a C++ library
# add_library(${PROJECT_NAME}
# src/${PROJECT_NAME}/testPath.cpp
# )
add_executable(${PROJECT_NAME}_node src/test.cpp)
The linking error I'm getting :
undefined reference to « ros::package::getPath(std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&) »
Any leads on how to make this work?