ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

custom message fails to build; no such file or directory

asked 2018-10-26 22:07:00 -0500

I followed the custom message documentation to the letter, and searched all the related questions on here, and unfortunately I am still stuck. Could you please have a look?

I am getting the same error building in Ubuntu 14.04 and 16.04, both running Kinetic.

All my packages that have custom messages fail to build (catkin_make exits with error). The custom message definition are part of the package, and are not from another package. The error reason is the same for all the packages with custom messages (from my limited understanding the .msg file is not found for some reason): fatal error: ... : No such file or directory ... > image description

image description

The package organization follows the documentation: image description

where the custom message file is called my_msg.msg and is inside the msg directory. The contents of my_msg.msg are not suspect either:

int32 my_int
float64 my_float

The package.xml does contain the needed lines:


The CMakeLists.txt contains everything the documentation mentions, and I even ran catkin_create_pkg test to make sure all the items are arranged in the correct order. Here is the file:

cmake_minimum_required(VERSION 2.8.3)


find_package(catkin REQUIRED COMPONENTS 


generate_messages(DEPENDENCIES std_msgs )

catkin_package(CATKIN_DEPENDS message_runtime)

include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(custom_msg_subscriber src/custom_msg_subscriber.cpp)

target_link_libraries(custom_msg_subscriber ${catkin_LIBRARIES})

and in the source code (file name is custom_msg_subscriber.cpp and it is inside the src directory), I am refrencing the custom message as #include <g_custom_messages/my_msg.h>, and am accessing the data via:

void poseMessageReceived(const g_custom_messages::my_msg &msg) 
    storeInt = msg.my_int;
    storeFloat = msg.my_float;

All the web search gymnastics I did have not helped. Could you please let me know why am I getting an error?

edit retag flag offensive close merge delete



Please check the catkin documentation on how to do this.

I'm fairly certain you're missing the add_dependencies(..) bit to let CMake know that custom_msg_subscriber depends on the msgs having been generated.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-27 05:04:31 -0500 )edit

Additionally: for the future: please don't post screenshots of terminals. It's all text, so you can just copy-paste it into your question.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-27 05:06:35 -0500 )edit

And for reference: updating the CMakeLists.txt of nodes using your custom message is explained in the next tutorial.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-27 05:09:09 -0500 )edit

@gvdhoorn Thank you very much for helping. I am learning ROS on my own and I really appreciate your help. Thank you!

BuilderMike gravatar image BuilderMike  ( 2018-10-27 12:39:12 -0500 )edit

No problem. Good to hear you got things to work.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-28 05:38:53 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-10-27 12:37:17 -0500

updated 2018-10-27 12:38:06 -0500

gvdhoorn was absolutely right. Thank you.

If you follow the msg and srv tutorial ( ), which is what I did, the only mention of add_dependencies(...) is in a link at the end of section 5... which I must have missed. When looking over the next tutorial (as gvhoorn pointed out. see: ), you can see how add_dependencies(source_file_name package_name_generate_messages_cpp) is used to build projects with custom message.

adding add_dependencied(...) to all the CMakeLists.txt in the packages with custom messges fixed my catkin build problems.

edit flag offensive delete link more


Hi, I hade the same problem and when I added the 'add_dependencied' some compilation errors were fixed. But one type of error remains, it seems that the namespace declared in the generated h (msg_name.h) does not exist. The scenario I have is the following:

in file foo.h
    \#include "msg_name.h"
    namespace_in_h_file::msg_name foo;

This compiles 9 times of 10 with catkin build and the error is that namespace_in_h_file is not a type. Any tips on how to proceed?

adde gravatar image adde  ( 2020-03-25 03:22:10 -0500 )edit

yes, this do fix my problem. My code can change can be found here.

Cullen SUN gravatar image Cullen SUN  ( 2022-08-15 12:44:50 -0500 )edit

Question Tools

1 follower


Asked: 2018-10-26 22:07:00 -0500

Seen: 10,684 times

Last updated: Oct 27 '18