I did the exercise like the solution.
this is what happened while compiling.
Please try try following and run
rm -rf ~/catkin_ws/build/ ~/catkin_ws/devel/
If this doesn’t work, please check that you don’t have 2 or more packages with the same name. When checking for duplicate package names, please ensure you check the
package.xml files in addition to the package folder names.
I removed the folders and compiled again, but still failed. it says
then i moved away my_cpp_class folder, keeping my_custom_srv_msg_pkg folder, and ran catkin_make, it succeeded.
then I move back my_cpp_class folder and ran catkin_make, it failed again:
is it because of the compiling order of these two packages?
but i can compile my_custom_srv_msg_pkg and my_cpp_class separately. and once i try to get the info, it says
CMakeLists.txt to ensure you are not using the same names in the package OR custom message name. In fact, the error message is already telling you that is the problem.
You probably created one package by copying over the other one. If you created both packages with
catkin_create_pkg, this problem is less likely to occur.
If you still cannot move forward, it’s better to
- back up the source files in the projects (do not backup
package.xml, as they are the suspects here). The folders in your package that should be backed up are usually
- create the packages again with
- Copy over the source files
- Carefully modify
- If both packages contain custom messages, ensure they don’t share the same name.
- Compile and source the workspace again.
To add to @bayodesegun’s excellent reply:
Even after having worked with ROS for a while and reusing lots of code (we all do it), It can be really helpfull to start with a fresh
package.xml and to add elements needed one by one, until the compiling works. It can take a while to fully understand what does what and why it is needed. It took me a while. Just reusing old files and adjusting may work at times, but it doesnt fully teach you the inner workings and you might add things that are unneccesary. Just food for thought, keep learning and coding!
When you have to troubleshoot compiling a single package, it might be smart to only build this single package, in order to save time. Check out this link to see how: