Robotics StackExchange | Archived questions

Custom message header not found C++

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)
project(shelflocation_state_coordinator)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  message_generation
)

add_message_files(
   DIRECTORY msg
   FILES
   Num.msg
 )

generate_messages(
   DEPENDENCIES
   std_msgs
)

catkin_package(
 INCLUDE_DIRS include
 CATKIN_DEPENDS message_runtime std_msgs

)

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)



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.

Asked by Spyro on 2020-06-25 14:41:34 UTC

Comments

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?

Asked by Teo Cardoso on 2020-06-25 17:33:36 UTC

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

Yes there is thé header file : Num.h

Asked by Spyro on 2020-06-25 17:43:50 UTC

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

#include "my_package_name/Num.h"

or

#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.

Asked by Teo Cardoso on 2020-06-25 18:01:18 UTC

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

Asked by Thomas D on 2020-06-25 20:08:18 UTC

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.

Asked by Thomas D on 2020-06-25 20:12:42 UTC

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

Asked by Spyro on 2020-06-26 02:42:06 UTC

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.

Asked by Mario Garzon on 2020-06-26 03:44:25 UTC

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?

Asked by Weasfas on 2020-06-27 04:52:28 UTC

Hello all,

I've tried all your suggestions but nothing works, unfortunately.

Asked by Spyro on 2020-06-27 11:52:06 UTC

So if catkin_make does not give you any errors, this must be something realted to the IDE configuration. is this usefull somehow?

Asked by Weasfas on 2020-06-27 12:08:30 UTC

Hi, i think also that is from my IDE, but it's strange because it works fine with sevice and client and custom messages.

Anyway, thank you very much for your help guys i'll let you know if i solve the problem.

Asked by Spyro on 2020-06-30 08:11:17 UTC

Can you edit your question and put the output of this at the bottom? roscd shelflocation_state_coordinator; ls -R That will help us determine your package layout. There is a tutorial on creating a package and a wiki about packages and even some best practices.

Asked by Thomas D on 2020-06-30 10:21:36 UTC

Answers