Robotics StackExchange | Archived questions

Migrating a custom library package used outside of ROS

Hi all,

We have a custom ROS package which exposes ROS services to the outside world (so as to let the app we are developing call ROS services). The ROS package and app used to work fine under indigo (Ubuntu 14.04), now we are migrating to kinetic (Ubuntu 16.04) and it did not work straight away: the compiler cannot find the #include "ros/ros.h" and #include <geometry_msgs/Pose.h>. It turns out that we had to add the following lines to our app's CMakeLists.txt in order to have the app compile:

include_directories( /opt/ros/kinetic/include )
link_directories( /opt/ros/kinetic/lib )

which is ugly and problably not the intended way.

Has anything changed in kinetic regarding the external use of ROS? We did not find much about this in the migration guides (link here and here). What should we actually do, rather than the CMake include and link instructions above? Anyone knows more about the problem?

As a reference, here are the CMakeLists.txt and package.xml files of the ROS package:

package.xml:

<?xml version="1.0"?>
<package format="2">
  <name>lc_toolkitLink</name>
  <version>0.0.1</version>
  <description>Tools for linking the toolkit with ROS.</description>
  <maintainer email="are@lescompanions.com">Antoine Rennuit</maintainer>
  <author email="are@lescompanions.com">Antoine Rennuit</author>
  <license>Proprietary</license>

  <buildtool_depend>catkin</buildtool_depend>

  <depend>roscpp</depend>
  <depend>std_msgs</depend>
  <depend>geometry_msgs</depend>
  <depend>lc_control</depend>
</package>

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(lc_toolkitLink)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

################################################################################
# Find packages.

# Eigen.
# NOTE: for reasons we do not understand it is not possible to set
#       CMAKE_MODULE_PATH as a relative path (although we do it in the toolkit)
#       hence we use function get_filename_component() to transform the relative
#       path to an absolute path.
get_filename_component(LC_CMAKE_FOLDER_PATH "../../../../CMake" ABSOLUTE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LC_CMAKE_FOLDER_PATH})
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ../../../../../Dependencies/Eigen/v3.2.0)
find_package(Eigen3 REQUIRED)

# Catkin.
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs geometry_msgs lc_control)

################################################################################
catkin_package(
    INCLUDE_DIRS .
    LIBRARIES lc_toolkitLink
    CATKIN_DEPENDS roscpp std_msgs geometry_msgs lc_control
)

################################################################################
# Headers.
include_directories(
    ${catkin_INCLUDE_DIRS}
    ${EIGEN3_INCLUDE_DIR}
    ../../../../ # This path is used to find headers from [Core] and [System].
    )

################################################################################
# Dependencies.
#add_subdirectory(../../../../Core ../../Core)

################################################################################
# Binaries.
add_library(
    lc_toolkitLink

    src/RosBase.h
    src/RosBase.cpp

    src/RosFrameSubscriber.h
    src/RosFrameSubscriber.cpp

    src/RosServices.h
    src/RosServices.cpp
    )
add_dependencies(lc_toolkitLink ${catkin_EXPORTED_TARGETS})
target_link_libraries(lc_toolkitLink
    ${catkin_LIBRARIES}
    Core)

################################################################################
# Install.
install(TARGETS lc_toolkitLink DESTINATION lib)

and both CMakeLists.txt of the app:

Top level CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
cmake_policy(SET CMP0015 NEW)

# Projet. 
project(ToolKit)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

#SET( CMAKE_BUILD_TYPE Debug )

find_package(catkin REQUIRED COMPONENTS rtt_ros)

set(CMAKE_AUTOMOC ON) # Instruct CMake to run moc automatically when needed.
set(CMAKE_PREFIX_PATH ../Dependencies/Qt/v5.9.1/5.9.1/gcc_64)

find_package(Qt5Widgets        REQUIRED)
find_package(Qt5Core           REQUIRED)
find_package(Qt5Gui            REQUIRED)
find_package(Qt5OpenGL         REQUIRED)
find_package(Qt5Quick          REQUIRED)
find_package(Qt5Qml            REQUIRED)
find_package(Qt5QuickControls2 REQUIRED)

#include_directories( /opt/ros/kinetic/include )
#link_directories( /opt/ros/kinetic/lib )

# Find dependencies.
set(CMAKE_MODULE_PATH ../src/CMake)
find_package(Eigen3 REQUIRED)
set(CMAKE_PREFIX_PATH ../Dependencies/pcl/v1.8.1)
find_package(PCL 1.7 REQUIRED COMPONENTS common io filters)
set(CMAKE_PREFIX_PATH ../Dependencies/gtest/v0a439623)
find_package(GTest REQUIRED)
set(CMAKE_PREFIX_PATH ../Dependencies/OpenSceneGraph/v3.4.1)
find_package(OpenSceneGraph 3.4.1 REQUIRED
    osg
    osgGA
    osgDB
    osgUtil
    osgText
    osgViewer
    OpenThreads
    )

set(QT_DIR ../../Dependencies/Qt/v5.9.1/5.9.1/gcc_64) #TODO: use find_package() for all dependencies.
set(STEPCODE_INSTALL_DIR ../../Dependencies/sc-install)

# Add subfolders.
add_subdirectory(Core)
add_subdirectory(System)
add_subdirectory(DataModel)
add_subdirectory(SceneGraph)
add_subdirectory(TkRenderer)
add_subdirectory(UnitTests)
add_subdirectory(ToolKitApp)
#add_subdirectory(Importer)

Lower level CMakeLists.txt:

project(SceneGraph)

# List sources.
set(${PROJECT_NAME}_headers
    RosFrameSubscriberNode.h
)

set(${PROJECT_NAME}_sources
    ...
    RosFrameSubscriberNode.cpp
    ...
)

# Headers.
include_directories(
    ../ ${EIGEN3_INCLUDE_DIR}
    ${PCL_INCLUDE_DIRS}
    ../catkin_ws/src/le_painters_companion/lc_toolkitLink/src)

# Link.
link_directories(
    ${PCL_LIBRARY_DIRS})

add_definitions(${PCL_DEFINITIONS})

find_library(LC_TOOLKIT_LINK   NAMES "lc_toolkitLink"   PATHS ../catkin_ws/install/lib)
if (${LC_TOOLKIT_LINK})
    message(FATAL_ERROR "COULD NOT find library lc_toolkitLink")
endif()

# Output library.
add_library(${PROJECT_NAME} STATIC ${${PROJECT_NAME}_headers} ${${PROJECT_NAME}_sources})

# Linker.
target_link_libraries(${PROJECT_NAME}
    DataModel

    ${PCL_COMMON_LIBRARIES}
    ${PCL_IO_LIBRARIES}

    ${LC_TOOLKIT_LINK})

Kind regards,

Olof and Antoine.

Asked by arennuit on 2018-07-13 08:25:00 UTC

Comments

Answers