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

Unable to link ros::package::getPath

asked 2022-05-03 08:11:56 -0500

Vic gravatar image

updated 2022-05-04 02:20:55 -0500

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2022-05-03 11:00:36 -0500

gvdhoorn gravatar image

updated 2022-05-03 11:01:11 -0500

Where do you call target_link_libraries(... ${catkin_LIBRARIES}) in your CMakeLists.txt?

edit flag offensive delete link more

Comments

You were right. Adding

target_link_libraries(${PROJECT_NAME}_node
   ${catkin_LIBRARIES}
)

in the CmakeLists.txt fixed the issue. I expected it to be done automatically when created the package. Thanks

Vic gravatar image Vic  ( 2022-05-04 02:20:01 -0500 )edit

As @gvdhoorn pointed, I was missing the target_link_libraries in CmakeList.txt

Vic gravatar image Vic  ( 2022-05-04 02:22:05 -0500 )edit
2

If gvdhoorn answered your question, please accept it as an answer. Thanks in advance

Joe28965 gravatar image Joe28965  ( 2022-05-04 06:49:20 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-05-03 08:11:56 -0500

Seen: 661 times

Last updated: May 04 '22