0
$\begingroup$

Rosanswers logo

I'm trying to do the same as this example : https://answers.ros.org/question/39523/rospackagegetpath-problem/

The function is documented here : http://docs.ros.org/en/jade/api/roslib/html/c++/namespaceros_1_1package.html

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="[email protected]">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, std::allocator > const&) »

Any leads on how to make this work?


Originally posted by Vic on ROS Answers with karma: 71 on 2022-05-03

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by gvdhoorn with karma: 86574 on 2022-05-03

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by Vic on 2022-05-04:
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

Comment by Vic on 2022-05-04:
As @gvdhoorn pointed, I was missing the target_link_libraries in CmakeList.txt

Comment by Joe28965 on 2022-05-04:
If gvdhoorn answered your question, please accept it as an answer. Thanks in advance

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.