Custom services header file is not found

I am experiencing an issue exactly like the one found here, but maybe I can re-explain the steps that led me to the issue. Every package in my workspace can no longer can find header files for any of my custom service messages.

I was able to compile and run my packages, I logged off and when I came back I encountered this error:
/home/user/catkin_ws/src/my_cpp_class/src/bb8_move_duration_srv_class.cpp:2:42: fatal error: my_cpp_class/durationservice.h: No such file or directory

The package that is causing error was not a package I was working on at the time. If I delete this package and try catkin make, then the next package with custom service messages raises this same error.

Now, if I do the following then everything works:

  • comment out the add executable lines in my makefile
  • compile the package
  • source devel/setup.bash
  • uncomment the add executable lines
  • recompile

What is puzzling to me is that all of these packages (makefiles, launch, executables, etc.) were not edited and working before encountering this error.

I fixed this issue by going to another course and then returning.

@rmmilner sounds like a sourcing issue. Just running
source devel/setup.bash
Should fix it. When switching chapter and returning, this is done automatically. @bayodesegun Perhaps you should check that the sourcing is done when reloading a session.

Strange error here. It could be that your files for the course were not fully loaded at the time the error was happening.

Anyways, should it happen again, please let us know.

@simon.steinmann91 I tried sourcing and it would not fix the issue.

Hi @rmmilner is this issue coming up again?

@bayodesegun

Yes this exact issue has happened again. I created a new package, did catkin_make and now some old package from the first unit can’t find the header-file for my custom service message. This package I haven’t touched for a long while.

However, this time, leaving the module and returning did not fix the issue. I had to comment the executable lines, make, source, uncomment lines, and make again to have it compile correctly.

I have discovered that letting the module ‘time-out’ is what causes this. When I leave the window open for too long and it disconnects, this is when it happens. Leaving the module normally does not cause the error.

Hi @rmmilner,

Sorry for the trouble. We’ll have a look at the timeout process.

In the meantime, should it happen again, can you try, in the catkin_ws directory:

# refresh the build and devel folders
rm -rf build/ devel/
catkin_make
source devel/setup.bash

I tried this and I couldn’t get past the make step, same error.

Please post the exact error you are seeing now. It might be another reason or just that your CMakeLists.txt and/or pacakage.xml is/are not properly setup.

@bayodesegun

@rmmilner

You are trying to import a message from another package my_cpp_class. Please take note of the following:

  1. To do this, you needed to have added my_cpp_class as a dependency when creating the package, i.e. catkin_create_pkg your_package_name roscpp my_cpp_class other_dependencies.
  2. For the Services Quiz (and other quizzes), you should create the custom message within the quiz package itself rather than import it from another package. Yeah, we know about code reuse but just want to keep things simple for the automatic grader. Also, you get to practise creating a custom message again :wink:.

Please adjust your package and let us know how it goes.

Maybe I am misunderstanding but the service was created in the package that I am using it in.

Oh, I see.

Did you follow the guide for preparing CMakeLists.txt and package.xml? From the CMakeLists.txt you shared, I can see the following are missing:

  • std_msgs is missing in find_package. And do you really need geometry_msgs for building your custom message?
  • catkin_package is empty? Why?
  • Did you edit package.xml as indicated?

I suggest that you carefully review the section about creating custom service messages in the notebook (section titled How to Prepare CMakeLists.txt and package.xml for Custom Service Compilation in Unit Understanding ROS Services - Server), carefully make needed changes and then let us know if you still have problems.

PS: before compiling again, don’t forget to rm -rf build/ devel/.