ERROR: Cannot load message class for [msg_package/mymsg]. Are your messages built?
Hello there. I have a program written in C++ that (among others) publishes a message, whose type is defined in a separate package (package that contains the message: msg_package, message name: mymsg, package that contains my node: mypkg, the cpp file with my node: subscriber). I have no problem with catkin_make or when running the node. However when I type rostopic echo /mytopic (the topic in which the node publishes the message), I get the following error:
ERROR: Cannot load message class for [msg_package/mymsg]. Are your messages built?
When I type rosmsg show msg_package/mymsg, it prints the fields of my message and also when I type rostopic info /mymsg it shows the type of message published.
Here are is my CMakeLists.txt: (there's also another message called "ImageSet.msg" defined in a msg folder inside the mypkg directory, but I don't use that)
cmake_minimum_required(VERSION 2.8.3)
project(mypkg)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
cv_bridge
image_transport
message_generation
sensor_msgs
msg_package
)
find_package( PCL REQUIRED )
include_directories( ${catkin_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS} )
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_message_files(DIRECTORY msg
FILES ImageSet.msg
)
generate_messages(DEPENDENCIES sensor_msgs)
catkin_package(CATKIN_DEPENDS cv_bridge image_transport message_runtime sensor_msgs)
find_package(OpenCV)
include_directories(include ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
add_executable(subscriber src/subscriber.cpp)
add_dependencies(subscriber ${catkin_EXPORTED_TARGETS} ${${PROJECT_NAME}_EXPORTED_TARGETS})
target_link_libraries(subscriber ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} ${PCL_LIBRARIES})
install(FILES
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
Here's my package.xml file:
<?xml version="1.0"?>
<package format="2">
<name>mypkg</name>
<version>0.0.0</version>
<description>The mypkg package</description>
<maintainer email="bla@todo.todo">bla</maintainer>
<license>TODO</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>rospy</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<build_depend>cv_bridge</build_depend>
<build_depend>image_transport</build_depend>
<build_depend>message_generation</build_depend>
<build_depend>opencv2</build_depend>
<build_depend>sensor_msgs</build_depend>
<exec_depend>cv_bridge</exec_depend>
<exec_depend>image_transport</exec_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend>opencv2</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<build_depend>pcl_conversions</build_depend>
<build_depend>pcl_ros</build_depend>
<build_export_depend>pcl_conversions</build_export_depend>
<build_export_depend>pcl_ros</build_export_depend>
<build_export_depend>sensor_msgs</build_export_depend>
<exec_depend>pcl_conversions</exec_depend>
<exec_depend>pcl_ros</exec_depend>
<build_depend>libpcl-all-dev</build_depend>
<exec_depend>libpcl-all</exec_depend>
<depend>msg_package</depend>
<export>
</export>
</package>
I'm using ROS Melodic on Ubuntu 18.04. Thanks in advance.