Ask Your Question

custom message fails to build; no such file or directory

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

BuilderMike gravatar image

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 imagegvdhoorn ( 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 imagegvdhoorn ( 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 imagegvdhoorn ( 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 imageBuilderMike ( 2018-10-27 12:39:12 -0500 )edit

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

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

1 Answer

Sort by ยป oldest newest most voted

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

BuilderMike gravatar image

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


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

Seen: 1,011 times

Last updated: Oct 27 '18