Exercise P1 how can I fix this compiling problem?

I did the exercise like the solution.
this is what happened while compiling.

Hi @wangxiaolong0830,

Please try try following and run catkin_make again.

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 CMakeLists.txt and 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

Check the 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 CMakeLists.txt or package.xml, as they are the suspects here). The folders in your package that should be backed up are usually src, launch, msg, action.
  • create the packages again with catkin_create_pkg...
  • Copy over the source files
  • Carefully modify CMakeLists.txt and package.xml as required.
  • If both packages contain custom messages, ensure they don’t share the same name.
  • Compile and source the workspace again.
1 Like

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 CMakeLists.txt and 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! :slight_smile:

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:

1 Like