Ask Your Question

How to add C++ code into ROS package

asked 2019-10-04 12:49:16 -0600

UR5e gravatar image

updated 2019-10-04 12:56:01 -0600

jayess gravatar image

I am properly executing the moveit_tutorial for the move_group_interface example at Move Group C++ Interface

The example code is in just one file, move_group_interface_tutorial.cpp. Is launched as

ros@ros-VirtualBox:~$ roslaunch moveit_tutorials move_group_interface_tutorial.launch

Then, I would like to create a cpp file in order to perform some coding. To test if it will be properly compiled, I just copy the example file and renamed it to test.cpp in the same folder. Then, I perform catkin_make after adding this line in CMakeLists.txt:

add_executable(moveit_tutorials doc/move_group_interface/src/test.cpp)

However, I am getting errors because of undefined references:

[ 74%] Building CXX object moveit_tutorials/CMakeFiles/moveit_tutorials.dir/doc/move_group_interface/src/test.cpp.o

[ 75%] Linking CXX executable moveit_tutorials CMakeFiles/moveit_tutorials.dir/doc/move_group_interface/src/test.cpp.o: In function main': test.cpp:(.text+0x46c): undefined reference toros::init(int&, char**, std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&, unsigned int)'

I am quite new in ROS and, in general, I would like to know how should I add a C++ code into an existing node package, following with the example.

What should I do to compile and rosrun the code instead of the roslaunch done in the example. Or the proper approach to do a launch file. Thank you.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-10-04 13:04:38 -0600

Rayman gravatar image

You are not linking your binary anything, so there are references that are not found. Somthing like this is missing:

target_link_libraries(moveit_tutorials ${catkin_LIBRARIES})

Here is more info:

edit flag offensive delete link more


I already tried but the error is the same:

[ 75%] Linking CXX executable moveit_tutorials
CMakeFiles/moveit_tutorials.dir/doc/move_group_interface/src/test.cpp.o: In function `main':
test.cpp:(.text+0x46c): undefined reference to `ros::init(int&, char**, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'
UR5e gravatar image UR5e  ( 2019-10-04 15:31:10 -0600 )edit

If you included the target_link_libraries and it still doesn't work, you can try the solutions described in:

Wilco Bonestroo gravatar image Wilco Bonestroo  ( 2019-10-04 16:20:57 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-10-04 12:49:16 -0600

Seen: 356 times

Last updated: Oct 04 '19