How to use a service defined in another package ?
Hi all,
I am facing a compilation problem when I try to include a service.h file in a node located in another package. Here is the architecture :
rosfond/
src/
my_nodes.cpp
include/
...
srv/
my_service.srv
hmi/
src/
my_other_nodes.cpp
include/
...
I want to use my_service
in the hmi
package, and especially include my_service.h
in my_other_nodes.cpp
. For that,
I wrote at the beginning of my_other_nodes.cpp
#include "rosfond/my_service.h"
.
I also use my_service
in my_nodes
.
When I try to compile my whole workspace, it fails. However, if I compile only rosfond
, it works. So the problem seems to be related to how I include/link my_service
in my_other_nodes
and in the hmi's CMakeLists.txt
.
Here are the CMakeLists.txt
and the package.xml
file of each package :
cmake_minimum_required(VERSION 2.8.3)
project(rosfond)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
add_service_files(DIRECTORY srv FILES my_service.srv)
generate_messages(DEPENDENCIES std_msgs)
catkin_package(
INCLUDE_DIRS include
# LIBRARIES rosfond
CATKIN_DEPENDS roscpp rospy std_msgs
# DEPENDS system_lib
)
include_directories(
${catkin_INCLUDE_DIRS}
include
)
add_executable(my_nodes src/my_nodes.cpp)
target_link_libraries(my_nodes
${catkin_LIBRARIES}
)
+++++++++++++++++++++++++++++++++++++++++++++++
<?xml version="1.0"?>
<package>
<name>rosfond</name>
<version>0.0.0</version>
<description>The rosfond package</description>
<maintainer email="ghost@todo.todo">ghost</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>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>
<run_depend>std_msgs</run_depend>
</package>
+++++++++++++++++++++++++++++++++++++++++++++++
cmake_minimum_required(VERSION 2.8.3)
project(hmi)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
generate_messages(DEPENDENCIES std_msgs)
catkin_package(
INCLUDE_DIRS include
# LIBRARIES hmi
CATKIN_DEPENDS roscpp rospy std_msgs
# DEPENDS system_lib
)
include_directories(
${catkin_INCLUDE_DIRS}
include
)
add_executable(my_other_nodes src/my_other_nodes.cpp)
target_link_libraries(my_other_nodes
${catkin_LIBRARIES}
)
+++++++++++++++++++++++++++++++++++++++++++++++
<?xml version="1.0"?>
<package>
<name>hmi</name>
<version>0.0.0</version>
<description>The hmi package</description>
<maintainer email="ghost@todo.todo">ghost</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_depend>rosfond</build_depend>
<run_depend>rosfond</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>
<run_depend>std_msgs</run_depend>
</package>
++++++++++++++++++++++++++++++++++++++++++++++++
The error message is : my_other_nodes.cpp : rosfond/my_service.h: No such file or directory
.
Thanking you in advance for your answers,
roach