ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

error in find_package(), when building with custom message.

asked 2018-11-07 11:14:06 -0500

mann gravatar image

updated 2018-11-07 17:54:27 -0500

Hello,

I have built ros2 from the latest stable source in Ubuntu 16.04. I was experimenting with colcon to build my own package as mentioned here and custom messages from this tutorial define custom interfaces/). My directory has the following structure:

--ros2_ws
      |--src
          |--pendulum_test
                      |--pendulum_controltwo
                            |--CMakeLists-.txt
                            |--package.xml
                            |--src
                                |--pendulum_demo.cpp
                      |--pendulumtwo_msgs
                            |--CMakeLists-.txt
                            |--package.xml
                            |--msg

my project is the same as pendulum_control and pendulum_msgs demo with appropriate name modifications in CMakeLists.txt and package.xml.

My build procedure is as follows:

  1. In the pendulumtwo_msgs directory, I used

    colcon build

    It was successful

  2. I sourced the pendulumtwo_msgs/install/local_setup.bash

  3. In the pendulum_controltwo directory I used "colcon build" again

This gave me the following error:

-------------------------error starts here--------------------------

Starting >>> pendulumtwo_control
--- stderr: pendulumtwo_control                         
CMake Error at CMakeLists.txt:22 (find_package):
  By not providing "Findpendulumtwo_msgs.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "pendulumtwo_msgs", but CMake did not find one.

  Could not find a package configuration file provided by "pendulumtwo_msgs"
  with any of the following names:

    pendulumtwo_msgsConfig.cmake
    pendulumtwo_msgs-config.cmake

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


---
Failed   <<< pendulumtwo_control    [ Exited with code 1 ]

Summary: 0 packages finished [2.34s]
  1 package failed: pendulumtwo_control
  1 package had stderr output: pendulumtwo_control

---------------------error ends here-------------------------------------

The problem looked very similar to this thread. I looked in the build log and noticed that CMAKE_PREFIX_PATH was set to: /ros2_ws2/src/pendulum_test/pendulumtwo_msgs/install/pendulum_msgs and the cmake files mentioned in the error are present in the recently mentioned install directory. I'm not sure if CMAKE_FIND_ROOT_PATH is being overrided some how as mentioned in the referenced thread.

I hope my build procedure is correct and any advice on solving this error would be appreciated.

package.xml:

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
  <name>pendulum_controltwo</name>
  <version>0.5.1</version>
  <description>Demonstrates ROS 2's realtime capabilities with a simulated inverted pendulum.</description>

  <maintainer email="mikael@osrfoundation.org">Mikael Arguedas</maintainer>

  <license>Apache License 2.0</license>

  <author>Jackie Kay</author>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <build_depend>rclcpp</build_depend>
  <build_depend>pendulumtwo_msgs</build_depend>
  <build_depend>rttest</build_depend>

  <exec_depend>rclcpp</exec_depend>
  <exec_depend>pendulumtwo_msgs</exec_depend>
  <exec_depend>rttest</exec_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)

project(pendulum_controltwo)

if(APPLE OR WIN32)
  message(STATUS "The pendulum_control demo is only supported on Linux. Package will not be built.")
  return()
endif()

find_package(ament_cmake REQUIRED)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(rclcpp REQUIRED)
find_package(pendulumtwo_msgs REQUIRED)
find_package(rttest)

include_directories(include)

if(NOT rttest_FOUND)
  message(STATUS "rttest not found. pendulum_control package will not be built.")
  return()
endif()

add_executable(pendulum_demo${target_suffix}
  src/pendulum_demo.cpp)
ament_target_dependencies(pendulum_demo${target_suffix}
  "pendulumtwo_msgs"
  "rclcpp${target_suffix}"
  "rttest ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-11-07 11:40:07 -0500

Dirk Thomas gravatar image

First you should invoke colcon build only once in the root of your workspace (ros2_ws in your case) instead of per package. This is described in the colcon tutorial you referenced.

Second there might be a bug in your CMake code or package manifest. If you would like help with that please share your code. Otherwise others can only guess.

edit flag offensive delete link more

Comments

Added CMake code and package.xml, Sorry about that.

mann gravatar image mann  ( 2018-11-07 17:58:12 -0500 )edit

Please share the same files for the pendulumtwo_msgs package.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-11-07 18:00:10 -0500 )edit

I just realized that the project name in package.xml of pendulumtwo_msgs is wrong. A silly mistake. Thank you for guiding me.

mann gravatar image mann  ( 2018-11-08 01:11:53 -0500 )edit
0

answered 2018-11-08 01:19:36 -0500

mann gravatar image

The "name" label in the package.xml had the wrong project name in pendulumtwo_msgs and hence it was showing an error in find_package label in CMakeLists.txt of pendulum_controltwo.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-11-07 11:14:06 -0500

Seen: 1,806 times

Last updated: Nov 08 '18