ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Ros2 Custom message - No such file or directory

asked 2021-12-08 06:22:49 -0600

bodka gravatar image

Hello everyone. I'm trying to build custom message in foxy distribution And gets an error: No such file or directory when i do colcon build.

the error is :

Starting >>> motor_interface
--- stderr: motor_interface                              /home/koby/spot_ws/src/Rexy_motor_control/src/motor_control.cpp:8:10: fatal error: motor_interface/msg/leg.hpp: No such file or directory
    8 | #include "motor_interface/msg/leg.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. make[2]: *** [CMakeFiles/motor_control.dir/build.make:63: CMakeFiles/motor_control.dir/src/motor_control.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:123: CMakeFiles/motor_control.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... make: *** [Makefile:141: all] Error 2
--- Failed   <<< motor_interface [0.84s, exited with code 2]

Summary: 0 packages finished [0.92s]   1 package failed: motor_interface   1 package had stderr output: motor_interface

The error only appears when I try to import the msg in a CPP file. When I import the msg in a python file it works fine.

the import in the cpp file:

#include <chrono>
#include <memory>
#include <cstdint>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int16.hpp"
#include "std_msgs/msg/int16_multi_array.hpp"
#include "motor_interface/msg/leg.hpp"
#include <JHPWMDriver/src/JHPWMPCA9685.h>
#include <vector>

the message is :

Leg.msg 
        string name
         int16[] id
         float32[] pos
         float32[] vel

the CmakeList:

cmake_minimum_required(VERSION 3.5)
project(motor_interface)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)


include_directories(include)
ament_export_include_directories(include)

find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(std_msgs REQUIRED)
#for the costom msg
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/Leg.msg"
  "msg/LegList.msg"
 )

add_executable(motor_control src/motor_control.cpp  include/JHPWMDriver/src/JHPWMPCA9685.cpp)
ament_target_dependencies(motor_control rclcpp  rclpy std_msgs)
target_link_libraries(motor_control ${catkin_LIBRARIES} i2c)


#target_link_libraries(motor_control ament_index_cpp::ament_index_cpp)
#rosidl_target_interfaces(motor_control ${PROJECT_NAME} 
#"rosidl_typesupport_cpp"
#)


install(TARGETS
  motor_control
  DESTINATION lib/${PROJECT_NAME})



# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # uncomment the line when a copyright and license is not present in all source files
  #set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # uncomment the line when this package is not in a git repo
  #set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()

the package:

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>motor_interface</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="kobylivne@gmail.com">spot-micro</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

<!--for the costom msg-->
  <build_depend>rosidl_default_generators</build_depend>
  <exec_depend>rosidl_default_runtime</exec_depend>
  <member_of_group>rosidl_interface_packages</member_of_group>


  <export>

    <build_type>ament_cmake</build_type>
    <depend>rclcpp</depend>
    <depend>std_msgs</depend>

  </export>
</package>

any idea how can i fix it?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2021-12-08 17:24:45 -0600

Geoff gravatar image

Most likely the problem is that the folder in which the generated header file is stored is not being added as an include directory to be searched.

The recommended practice when creating custom messages is to create a new package just for the messages. Then you can depend on that from the package that wants to use the messages, and by the time it gets compiled the custom messages' header files have been installed into the correct location to be found by the include file search.

Take a look at the example_interfaces package to see what a messages-only package looks like.

edit flag offensive delete link more

Comments

tanks for your replay. in the "example_interfaces" they did it with a new package for the messages as you דuggest and it work grate. i try to build a msg in the same pkg as my cpp file.

the leg.hpp file path are:

spot_ws/build/motor_control/rosidl_generator_cpp/motor_control/msg/leg.hpp

how do i add a path from the build folder in the ws?

bodka gravatar image bodka  ( 2021-12-09 05:55:05 -0600 )edit

Question Tools

Stats

Asked: 2021-12-08 06:22:49 -0600

Seen: 1,210 times

Last updated: Dec 08 '21