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

How to add C++ code into ROS package

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

UR5e gravatar image

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

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
1

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

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: http://wiki.ros.org/catkin/CMakeLists...

edit flag offensive delete link more

Comments

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 -0500 )edit
1

If you included the target_link_libraries and it still doesn't work, you can try the solutions described in: https://answers.ros.org/question/2919...

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

Question Tools

1 follower

Stats

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

Seen: 1,160 times

Last updated: Oct 04 '19