Exercise 3.2 - Confused - linking error

I seem to be having an issue with a linking error that doesn’t seem to make sense to me.

execute_trajectory.cpp:(.text+0x1ce): undefined reference to `ros::package::getPath(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)’

I’ve traced it to the following line in the solution .cpp file:
trajectory.request.file = ros::package::getPath(“iri_wam_reproduce_trajectory”) + “/config/get_food.txt”;

if I replace the right side of the assignment with the actual path, it works… if I try to use the getPath function it errors out.


Hi @tchav006,

First of all, welcome to the community!

Now to your question. The hint here is the part of the error that says undefined reference to ros::package::getPath…so here are the things you can check:

  • Did you #include <ros/package.h>? in your C++ program?
  • Did you modify your CMakeLists.txt as mentioned in the notebook? Excepts:

In order to be able to properly compile the the ros::package::getPath() function, you will need to add dependencies to the roslib library. You can do that by modifying the find_package() function in the CmakeLists.txt file. Like this:

find_package(catkin REQUIRED COMPONENTS
  • Did you compile your package with catkin_make and then source devel/setup.bash on every shell after that?

Please let’s know how it goes. Cheers!

1 Like