Custom action message Fatal error: No such file or directory

Trying to make action server with custom message, but keep getting error on build process.

fatalerror: test_custom_action_msg_pkg/custom_action_msg.h: No such file or directory

Without test_custom_action_msg.cpp built finishes correctly and

rosmsg list | grep test_custom_action_msg_pkg

returns:

test_custom_action_msg_pkg/custom_action_msgAction
test_custom_action_msg_pkg/custom_action_msgActionFeedback
test_custom_action_msg_pkg/custom_action_msgActionGoal
test_custom_action_msg_pkg/custom_action_msgActionResult
test_custom_action_msg_pkg/custom_action_msgFeedback
test_custom_action_msg_pkg/custom_action_msgGoal
test_custom_action_msg_pkg/custom_action_msgResult

source devel/setup.bash

Does not help.

custom_action_msg.action

#goal
string goal
---
#result
string result
---
#feedback
string feedback

test_custom_action_msg.cpp

#include <ros/ros.h>
#include "test_custom_action_msg_pkg/custom_action_msg.h"

int main(int argc, char** argv)
{
  ROS_INFO("Test start");  
  ros::spin();
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.0.2)
project(test_custom_action_msg_pkg)

find_package(catkin REQUIRED COMPONENTS 
  actionlib
  actionlib_msgs
  roscpp 
)

add_action_files(
   FILES
   custom_action_msg.action
)

generate_messages(
  DEPENDENCIES
	actionlib_msgs
)

catkin_package(
  CATKIN_DEPENDS 
  actionlib 
  actionlib_msgs
  roscpp
)

add_executable(test_custom_action_msg src/test_custom_action_msg.cpp)
add_dependencies(test_custom_action_msg ${test_custom_action_msg_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(test_custom_action_msg ${catkin_LIBRARIES})

add_dependencies(test_custom_action_msg test_custom_action_msg_pkg_generate_messages_cpp)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

package.hml

<?xml version="1.0"?>
<package format="2">
  <name>test_custom_action_msg_pkg</name>
  <version>0.0.0</version>
  <description>The test_custom_action_msg_pkg package</description>

  <maintainer email="user@todo.todo">user</maintainer>
 
  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>
  
  <build_depend>actionlib</build_depend>
  <build_depend>actionlib_msgs</build_depend>
  <build_depend>roscpp</build_depend>
  
  <build_export_depend>actionlib</build_export_depend>
  <build_export_depend>actionlib_msgs</build_export_depend>
  <build_export_depend>roscpp</build_export_depend>
  
  <exec_depend>actionlib</exec_depend>
  <exec_depend>actionlib_msgs</exec_depend>
  <exec_depend>roscpp</exec_depend>

  <export>
  </export>
</package>

So what i doing wrong?

Hi @shatodor ,

Are you compiling the custom message and your package in the same terminal?
If you re not, then you might get this error. This happens when you compile your custom message package on one terminal and launch the other package from another terminal.

You must first compile the action message package.
Then source the workspace on all terminals that you are using.

I hope this helps.

Regards,
Girish

Hello @girishkumar.kannan

I doing all commands in one terminal window.

First I comment next lines in CMakeLists.txt :

#add_executable(test_custom_action_msg src/test_custom_action_msg.cpp)
#add_dependencies(test_custom_action_msg ${test_custom_action_msg_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(test_custom_action_msg ${catkin_LIBRARIES})

#add_dependencies(test_custom_action_msg test_custom_action_msg_pkg_generate_messages_cpp)

Then I exiqute next commands:

rm -rf build/ devel/
catkin_make --only-pkg-with-deps test_custom_action_msg_pkg
source devel/setup.bash
rosmsg list | grep test_custom_action_msg_pkg

Next I uncoment lines mension above and exiqute agane

catkin_make --only-pkg-with-deps test_custom_action_msg_pkg

And gain same Fatal error.

Can you check that the source files are placed in the right locations? The error indicates it cannot find certain files.

What files should I check?

Looking at this problem more closely, I see that the problem is that catkin_make is trying to build your C++ source before building the message. We have to get it to build the message first.

Add the following to your CMakeLists.txt and package.xml respectively.

  1. std_msgs, needed for generating the custom message.
generate_messages(
  DEPENDENCIES
	actionlib_msgs std_msgs
)

  1. Add <exec_depend>message_generation</exec_depend> to package.xml. This kind of tells it to generate the message first.

Still same Fatal error.

image

Hi @shatodor ,

Could you please post the full error output from compilation?

Also please post your updated CMakeLists.txt and package.xml.
I believe message_generation is not required for a package with only custom action message.

Regards,
Girish

Did you remove the build and devel folders before trying to recompile?

cd ~/catkin_ws
rm -rf build/ devel/
catkin_make

Also, I don’t know what you have in the include subdirectory of your package…I think you can remove that folder.

Hi @girishkumar.kannan!

cmake_minimum_required(VERSION 3.0.2)
project(test_custom_action_msg_pkg)

find_package(catkin REQUIRED COMPONENTS 
  actionlib
  actionlib_msgs
  roscpp 
)

add_action_files(
   FILES
   custom_action_msg.action
)

generate_messages(
  DEPENDENCIES
	actionlib_msgs
	std_msgs
)

catkin_package(
  CATKIN_DEPENDS 
  actionlib 
  actionlib_msgs
  roscpp
)

add_executable(test_custom_action_msg src/test_custom_action_msg.cpp)
add_dependencies(test_custom_action_msg ${test_custom_action_msg_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(test_custom_action_msg ${catkin_LIBRARIES})

add_dependencies(test_custom_action_msg test_custom_action_msg_pkg_generate_messages_cpp)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

<?xml version="1.0"?>
<package format="2">
  <name>test_custom_action_msg_pkg</name>
  <version>0.0.0</version>
  <description>The test_custom_action_msg_pkg package</description>

  <maintainer email="user@todo.todo">user</maintainer>
 
  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>

  <exec_depend>message_generation</exec_depend>
  
  <build_depend>actionlib</build_depend>
  <build_depend>actionlib_msgs</build_depend>
  <build_depend>roscpp</build_depend>
  
  <build_export_depend>actionlib</build_export_depend>
  <build_export_depend>actionlib_msgs</build_export_depend>
  <build_export_depend>roscpp</build_export_depend>
  
  <exec_depend>actionlib</exec_depend>
  <exec_depend>actionlib_msgs</exec_depend>
  <exec_depend>roscpp</exec_depend>
  

  <export>
  </export>
</package>

Yes, I did multiple times.

Deleted include subdirectory. It was empty.

Hi @shatodor ,

If the most recently posted contents of the CMakeLists.txt file is the actual contents of your file, then your file is missing some other commands for compilation.

You need to name your action file in CamelCase as per convention.
So your filename becomes CustomActionMsg.action instead of custom_action_msg.action.
Once you have changed the file name, you can import the message like:
#include "test_custom_action_msg_pkg/CustomActionMsgAction.h".

This change should get things working. Let me know if you still have issues.

Regards,
Girish

Hi @girishkumar.kannan

That helped. Thanks a lot!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.