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.
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?
Like This : #include "my_package_name/Num.msg"
Yes there is thé header file : Num.h
To include the message you use the header file, not the message file. You should use something like:
or
Try change to this and say the result, with works I add as an answer to close the topic.
To make text show up like code you can (i) indent by 4 spaces, or (ii) select text then click the button with
101010
.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 thanshelflocation_state_coordinator
, what does that other packagesCMakeLists.txt
look like? What makes you think you cannot includeNum.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.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
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 withcatkin_make
then sourcing thedevel/setup.bash
and finally launching the IDE from the command line.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?