ROS in 5 Days C++ Services Exercise 3.2 error

I copied the solution code for Exercise 3.2. When I go to build I’m getting the following error:

Errors     << services_32:make /home/user/catkin_ws/logs/services_32/build.make.007.log
/usr/bin/ld: CMakeFiles/execute_trajectory.dir/src/execute_trajectory.cpp.o: in function `main':
execute_trajectory.cpp:(.text+0x263): undefined reference to `ros::package::getPath(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/execute_trajectory.dir/build.make:102: /home/user/catkin_ws/devel/.private/services_32/lib/services_32/execute_trajectory] Error 1
make[1]: *** [CMakeFiles/Makefile2:221: CMakeFiles/execute_trajectory.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
cd /home/user/catkin_ws/build/services_32; catkin build --get-env services_32 | catkin env -si  /usr/bin/make --jobserver-auth=3,4; cd -

Beware of copying solutions as-is because they might have some bits missing so verbatim copy does work :wink:.

Based on the error message undefined reference to ros::package::getPath..., did you include the following in the source code?

#include <ros/package.h>

Yes, but the problem was that I did not add roslib to CMakeLists.txt. Thanks for the help. I copied after running into a bug in my code that turned out to be a syntax error.

2 Likes