Cannot find header file of custom service: No such file or directory

asked 2022-03-29 20:36:14 -0600

Kevin1719 gravatar image

updated 2022-03-30 03:18:27 -0600

Hi all, I'm having a package with some custom services, everything worked fine. But when others try to build my package with "catkin_make" command, it says that "No such file or directory" when it meets the line

#include <my_package/MyService.h>

I added the following line to CMakeLists.txt:

add_dependencies(foo my_package_generate_messages_cpp)

But it didn't work. I think above line only work if only the executables include header files. But in my case, I have some header files that declare libraries also use the custom services. So I commented all the files that included this line in CMakeLists.txt and built the services alone, then I uncommented those files and catkin_make again, everything were back to normal. It seems like the compiler didn't found the header files in directory my_package/devel/include.

Here is my CMakeList.txt:

cmake_minimum_required(VERSION 3.0.2)
project(my_behavior_tree)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  behaviortree_cpp_v3
  message_generation
  actionlib
  move_base_msgs
)

add_service_files(
  FILES
  TakePackage.srv
  SetDeliveryPoint.srv
  GoToPose.srv
  PauseRequest.srv
  CruiseMode.srv
  ChooseMode.srv
)

add_message_files(
  FILES
  OfficePose.msg
  DeliveryPose.msg
  RobotStatus.msg
)

generate_messages(
  DEPENDENCIES
)

catkin_package(
 INCLUDE_DIRS include
 LIBRARIES ${BEHAVIOR_TREE_LIBRARY}
 CATKIN_DEPENDS roscpp message_runtime
 DEPENDS
)

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

# Declare a C++ library
add_library(my_bt_lib src/control/delivery.cpp src/control/charge.cpp
            src/control/cruise.cpp
            src/reception/music.cpp src/reception/time_keeping.cpp
            src/reception/direction.cpp)

# Specify libraries to link a library or executable target against
target_link_libraries(my_bt_lib ${BEHAVIOR_TREE_LIBRARY})

add_executable(move_robot src/move_robot.cpp src/control/delivery.cpp
              src/control/charge.cpp src/reception/direction.cpp
              src/reception/music.cpp src/reception/time_keeping.cpp
              src/control/cruise.cpp)
target_link_libraries(move_robot ${catkin_LIBRARIES})
edit retag flag offensive close merge delete

Comments

Can you share your Cmake?

Hamid Didari gravatar image Hamid Didari  ( 2022-03-30 02:33:41 -0600 )edit

I just update the question, please take a look. Thank you very much.

Kevin1719 gravatar image Kevin1719  ( 2022-03-30 03:19:10 -0600 )edit

add this line at the end of your Cmake and try it again:

add_dependencies(move_robot  my_behavior_tree_generate_messages_cpp)
Hamid Didari gravatar image Hamid Didari  ( 2022-03-30 03:25:55 -0600 )edit