Custom message header not found C++

asked 2020-06-25 14:41:34 -0500

Spyro gravatar image

updated 2022-01-22 16:10:37 -0500

Evgeny gravatar image

Hello everybody,

I know that this question has been asked several times, I have looked at all the existing subjects but I have not found the solution to my problem.

I created a "Num.msg" message that I want to use, but I can't include its "Num.h" header because it can't be found.

I don't have any error when I do catkin_make.

here is my CmakeLists

cmake_minimum_required(VERSION 3.0.2)

find_package(catkin REQUIRED COMPONENTS



 CATKIN_DEPENDS message_runtime std_msgs



add_library(Channel src/Channel.cpp)
add_library(TX_DB src/TX_DB.cpp)
add_library(LimitSwitch src/LimitSwitch.cpp)
add_library(DrivingMotor src/DrivingMotor.cpp)
add_library(Encoder src/Encoder.cpp)
add_library(Shelf src/Shelf.cpp)
add_library(Display src/Display.cpp)
add_library(Curtain src/Curtain.cpp)
add_library(Location src/Location.cpp)

add_executable(Controller src/Controller.cpp)
target_link_libraries(Controller Location Display Curtain  Shelf Encoder DrivingMotor LimitSwitch TX_DB Channel ${catkin_LIBRARIES})

add_executable(publisher src/publisher.cpp)
target_link_libraries(publisher ${catkin_LIBRARIES})
add_dependencies(publisher ${${PROJECT_NAME}_EXPORTED_TARGETS})

Thank you.

edit retag flag offensive close merge delete


How are you trying to include the file in the code?

Could you check in the devel/include/{package_name} folder if there is any message header?

Teo Cardoso gravatar image Teo Cardoso  ( 2020-06-25 17:33:36 -0500 )edit

Like This : #include "my_package_name/Num.msg"

Yes there is thé header file : Num.h

Spyro gravatar image Spyro  ( 2020-06-25 17:43:50 -0500 )edit

To include the message you use the header file, not the message file. You should use something like:

#include "my_package_name/Num.h"


#include <my_package_name/Num.h>

Try change to this and say the result, with works I add as an answer to close the topic.

Teo Cardoso gravatar image Teo Cardoso  ( 2020-06-25 18:01:18 -0500 )edit

To make text show up like code you can (i) indent by 4 spaces, or (ii) select text then click the button with 101010.

Thomas D gravatar image Thomas D  ( 2020-06-25 20:08:18 -0500 )edit

What file are you trying to include the header shelflocation_state_coordinator/Num.h in? For the file that includes the message header, what package is it in? If it is a different package than shelflocation_state_coordinator, what does that other packages CMakeLists.txt look like? What makes you think you cannot include Num.h if you are not getting a compiler error? It would help to know your package layout, what commands you are running, and what the output is.

Thomas D gravatar image Thomas D  ( 2020-06-25 20:12:42 -0500 )edit

Still doesn't work with #include <my_package_name/Num.h> I'm trying to include the header int publisher.cpp file, it is in the same package (shelflocation_state_coordinator) Because my IDE is saying file not found (Clion) , so i can't even use my message type. What do you mean by package layout ? (sorry i'm beginner in ROS)

Thank you for you help

Spyro gravatar image Spyro  ( 2020-06-26 02:42:06 -0500 )edit

You said that you don't have any error when running catkin_make, that makes me think that the error only appears on your IDE is that right? If that's the case, have you tried compiling the ws with catkin_make then sourcing the devel/setup.bash and finally launching the IDE from the command line.

Mario Garzon gravatar image Mario Garzon  ( 2020-06-26 03:44:25 -0500 )edit

Hi all,

Just to be sure. I think that is a problem about package dependency, you need to tell explicitly to catkin the package needs a exported target from a custom message (For insntace the message header bindings). Can you try to add add_dependencies(some_target ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) to your cmake and test if that works?

Weasfas gravatar image Weasfas  ( 2020-06-27 04:52:28 -0500 )edit