Search code examples
cmakerosmsg

ROS - find_package - MSG in other local package


I work on ROS and I am blocked in CMAKE step. So explain

build
devel
src
  package_a
    node_a
      source
        node_a.cpp
    CMakeList.txt
    package.xml
  package_b
    msg
      msg_between_a_b.msg
    node_b
      source
        node_b.cpp
    CMakeList.txt
    package.xml

I am blocked in the step of CMakeList.txt for package_a. Package a need to know the message defined in package_b.

Error message from TERM console.

Add the installation prefix of "package_b" to CMAKE_PREFIX or set "package_b_DIR" to a directory containing one of the above files. If "package_b" provides a separate development package or SDK, be sure it has been installed.

I am (very) interesting of "package_b_DIR".

That is what I write in CMalkeList.txt:

# SEARCH package that already EXIST in /opt/ros
find_package(catkin REQUIRED COMPONENTS
 message_generation
 rostime
 roscpp
 std_msgs
 rosconsole
 roscpp_serialization)

# Add package PACKAGE_B (usefull) for MSG
find_package(catkin REQUIRED COMPONENTS
  package_b)

Very very thanks in advance !


Solution

  • Problem solved

    1. ROS shall find package_b.

    If true, you can find this file via this command:

    find ./ -type f -name "*Config.cmake"
    

    Result:

    ./build/package_b/catkin_generated/installspace/package_bConfig.cmake

    ./devel/share/package_b/cmake/package_bConfig.cmake

    If not, open CMakeList.txt and check IF:

    catkin_package(
    )
    

    Check success of build via catkin_make.

    2. Inform that package a need package b

    After inform package_a that need package_b. This information is in the package.xml of package_a:

    Find <build_depend> and inform that need package_b.

    <build_depend>package_b</build_depend>