Custom msg not found in another package

asked 2021-09-11 13:32:47 -0600

Sknet gravatar image

updated 2021-09-12 16:15:35 -0600

I am trying to use a custom msg in another package within the same workspace. I am getting the following error:

/home/kanete/knet_bot_ws/src/knet_bot_localization/src/knet_bot_odom.cpp:6:10: fatal error: knet_bot_msgs/EncoderSpeed.h: No such file or directory
    6 | #include <knet_bot_msgs/EncoderSpeed.h>

I am using Ubuntu 20.04 and ROS Noetic. I have generated a custom msg that can be found using rosmsg show.

   rosmsg show EncoderSpeed
[knet_bot_msgs/EncoderSpeed]:
std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
float32 right_wheel_rpm
float32 left_wheel_rpm

The CMakeList.txt of the package that needs to use the custom msg is:

cmake_minimum_required(VERSION 3.0.2)
project(knet_bot_localization)
add_compile_options(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
  nav_msgs
  roscpp
  std_msgs
  knet_bot_msgs
  tf
)
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES compute_cdist
  CATKIN_DEPENDS 
  roscpp 
  knet_bot_msgs
#  DEPENDS assimp Eigen mlpack
)
include_directories(
  ${catkin_INCLUDE_DIRS}
)
add_executable(knet_bot_odom src/knet_bot_odom.cpp)
target_link_libraries(knet_bot_odom ${catkin_LIBRARIES})
add_dependencies(knet_bot_odom ${catkin_EXPORTED_TARGETS})

The package.xml:

<?xml version="1.0"?>
<package format="2">
  <name>knet_bot_localization</name>
  <version>0.0.0</version>
  <description>The knet_bot_localization package</description>

  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>tf</build_depend>
  <build_depend>nav_msgs</build_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>knet_bot_msgs</build_depend>
  <build_export_depend>tf</build_export_depend>
  <build_export_depend>nav_msgs</build_export_depend>
  <build_export_depend>roscpp</build_export_depend>
  <build_export_depend>std_msgs</build_export_depend>
  <exec_depend>tf</exec_depend>
  <exec_depend>nav_msgs</exec_depend>
  <exec_depend>roscpp</exec_depend>
  <exec_depend>std_msgs</exec_depend>
  <exec_depend>knet_bot_msgs</exec_depend>

  <depend>knet_bot_sensors</depend>

  <export>


  </export>
</package>
  • I have tried removing /devel and /build and rebuilding.
  • I have tried generating the message first and then building the package that depends on it.
  • I have tried using add_dependencies(knet_bot_odom knet_bot_msgs_generate_messages_cpp)

It seems a little strange. I have been able to build this package in a different computer.

Any help would be really appreciated :) Thank you!

CMakeList.txt of package containing EncoderSpeed.msg:

cmake_minimum_required(VERSION 3.0.2)
project(knet_bot_msgs)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  actionlib
  actionlib_msgs
  std_msgs
  sensor_msgs
  geometry_msgs
  message_generation
)

## Generate messages in the 'msg' folder
 add_message_files(
   FILES
   EncoderSpeed.msg
 )

## Generate added messages and services with any dependencies listed here
  generate_messages(
    DEPENDENCIES
    actionlib
    actionlib_msgs
    std_msgs
    sensor_msgs
    geometry_msgs
  )

catkin_package(
  CATKIN_DEPENDS
  roscpp
  rospy
  std_msgs
  actionlib
  actionlib_msgs
  std_msgs
  sensor_msgs
  geometry_msgs
  message_generation
  message_runtime
)

package.xml of package containing EncoderSpeed.msg

<?xml version="1.0"?>
<package format="2">
  <name>knet_bot_msgs</name>
  <version>0.0.0</version>
  <description>The knet_bot_msgs package</description>

  <maintainer email="tuf01133@todo.todo">tuf01133</maintainer>

  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>message_generation</build_depend>
  <build_depend>actionlib</build_depend>
  <build_depend>actionlib_msgs</build_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>geometry_msgs</build_depend>
  <build_depend>sensor_msgs</build_depend>

  <build_export_depend>message_generation</build_export_depend>
  <build_export_depend>actionlib</build_export_depend>
  <build_export_depend>actionlib_msgs</build_export_depend>
  <build_export_depend>roscpp</build_export_depend>
  <build_export_depend>rospy</build_export_depend>
  <build_export_depend>std_msgs</build_export_depend>
  <build_export_depend>geometry_msgs</build_export_depend>
  <build_export_depend>sensor_msgs</build_export_depend>

  <exec_depend>message_runtime</exec_depend>
  <exec_depend>actionlib</exec_depend>
  <exec_depend>actionlib_msgs</exec_depend>
  <exec_depend>roscpp</exec_depend>
  <exec_depend>rospy</exec_depend>
  <exec_depend>std_msgs</exec_depend>
  <exec_depend>geometry_msgs</exec_depend>
  <exec_depend>sensor_msgs</exec_depend>

  <export>


  </export>
</package>
edit retag flag offensive close merge delete

Comments

Can you also include CMakeLists and package.xml of the package containingEncoderSpeed?

abhishek47 gravatar image abhishek47  ( 2021-09-12 02:10:03 -0600 )edit

Thank you. I have included those files.

Sknet gravatar image Sknet  ( 2021-09-12 16:20:25 -0600 )edit

In your CMakeLists can you include:

include_directories( ${catkin_INCLUDE_DIRS} )

and see if that helps

abhishek47 gravatar image abhishek47  ( 2021-09-17 01:21:01 -0600 )edit

Hi, yes this is included in the knet_bot_localization package. It is also included in the knet_bot_msgs package but I accidentally removed it when posting in the forum. I still get the same error :/

Sknet gravatar image Sknet  ( 2021-09-18 09:53:44 -0600 )edit