How to add C++ code into ROS package
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.