Ask Your Question
0

How to use custom defined messages in another package?

asked 2017-05-12 15:06:44 -0600

mayank gravatar image

updated 2017-05-13 12:49:12 -0600

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-05-12 15:36:33 -0600

Thomas D gravatar image

updated 2017-05-12 15:37:59 -0600

Does your bb/package.xml file exist? Do you depend on aa? In bb/CMakeLists.txt you do not have aa listed in find_package() or catkin_pkg/CATKIN_DEPENDS, which you will probably need.

edit flag offensive delete link more

Comments

I've converted this to an answer, as it is the answer.

@mayank: catkin/cmake doesn't know that there is a build-time dependency (and thus a required ordering when building) without the information that @Thomas D writes about. Add aa to the CATKIN_DEPENDS of bb at least.

gvdhoorn gravatar imagegvdhoorn ( 2017-05-13 02:45:12 -0600 )edit

See the catkin howto documentation for more info on this.

gvdhoorn gravatar imagegvdhoorn ( 2017-05-13 02:46:22 -0600 )edit

Yes, bb/package.xml exists and it contains 'aa' as build and run dependencies. Sorry forgot to include that in the question.

mayank gravatar imagemayank ( 2017-05-13 03:05:23 -0600 )edit

Btw (from the CMakeLists.txt of bb):

add_executable(listener src/src_aa.cpp)
...
add_dependencies(listener aa_generate_messages_cpp)

I'm assuming this is copy-pasta?

gvdhoorn gravatar imagegvdhoorn ( 2017-05-13 03:07:51 -0600 )edit

I added the project aa in both the places in bb/CMakeLists.txt but it says: 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?

mayank gravatar imagemayank ( 2017-05-13 03:12:05 -0600 )edit

Please edit your question and add (do not overwrite) the updated CMakeLists.txt and package.xml for both packages.

gvdhoorn gravatar imagegvdhoorn ( 2017-05-13 03:14:37 -0600 )edit

Yes @gvdhoorn it is mostly copy-paste.In fact this is my second project in ROS just after beginner-tutorials.

mayank gravatar imagemayank ( 2017-05-13 03:17:15 -0600 )edit
1
LIBRARIES aa

I see this in the CMakeLists.txt of both aa and bb, but you never actually create any libraries, only executables. Please remove that from your CMakeLists.txt.

gvdhoorn gravatar imagegvdhoorn ( 2017-05-13 03:58:49 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-05-12 15:06:44 -0600

Seen: 3,990 times

Last updated: May 13 '17