How to use custom defined messages in another package?
I am new to ros and was writing code to publish and listen to a custom message. I am running ROS kinetic on Debian machine.
In my workspace I have two package - aa and bb. aa has a message two_ints
as follows:
int16 a1
int16 b1
Both the packages use this message. When I catkin_make my workspace I get the following error in source of bb:
.../catkin_new/src/bb/src/src_bb.cpp:2:24: fatal error: aa/two_ints.h: No such file or directory
The CMakeLists.txt of aa is
cmake_minimum_required(VERSION 2.8.3)
project(aa)
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
message_generation
)
add_message_files(
FILES
two_ints.msg
)
generate_messages(
DEPENDENCIES
std_msgs
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES aa
CATKIN_DEPENDS roscpp std_msgs message_runtime
)
include_directories(
${catkin_INCLUDE_DIRS}
)
add_executable(talker src/src_aa.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
add_dependencies(talker aa_generate_messages_cpp)
And CMakeLists.txt of bb is
cmake_minimum_required(VERSION 2.8.3)
project(bb)
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES bb
CATKIN_DEPENDS roscpp std_msgs
)
include_directories(
${catkin_INCLUDE_DIRS}
)
add_executable(listener src/src_aa.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener aa_generate_messages_cpp)
Directory structure is:
catkin_new
-build
-devel
-src
-CMakeLists.txt
-aa
-msg
-two_ints.msg
-include
-src
src_aa.cpp
-...
-bb
-CMakeLists.txt
-src
-src_bb.cpp
-...
Please help me out. I have tried various things but in vain. Also talker gets built even though it also includes aa/two_ints.h. Why so? And two_ints.h is present in devel/aa/ directory.
EDIT: The aa/package.xml is:
<?xml version="1.0"?>
<package>
<name>aa</name>
<version>0.0.0</version>
<description>The aa package</description>
<license>TODO</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>message_generation</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>std_msgs</run_depend>
<run_depend>message_runtime</run_depend>
</package>
The `bb/CMakeLists.txt' is modified and is as follows:
cmake_minimum_required(VERSION 2.8.3)
project(bb)
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
aa #changed here
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES bb
CATKIN_DEPENDS roscpp std_msgs aa #changed here
)
include_directories(
${catkin_INCLUDE_DIRS}
)
add_executable(listener src/src_aa.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener aa_generate_messages_cpp)
The 'bb/package.xml' is:
<package>
<name>bb</name>
<version>0.0.0</version>
<description>The bb package</description>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>aa</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>std_msgs</run_depend>
<run_depend>aa</run_depend>
</package>
Now when I catkin_make the catkin_new workspace I get following error:
CMake Error at /home/mayank/Workspace/catkin_new/devel/share/aa/cmake/aaConfig.cmake:141 (message):
Project 'bb' tried to find library 'aa'. The library is neither a target
nor built/installed properly. Did you compile project 'aa'? Did you
find_package() it before the subdirectory containing its code is included?
Call Stack (most recent call first):
/opt/ros/kinetic/share/catkin/cmake/catkinConfig.cmake:76 (find_package)
bb/CMakeLists.txt:10 (find_package)
Looks like bb
is getting built before/in parallel with aa
. What am I missing?