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

Unable to include header files from another package

asked 2018-10-15 01:09:24 -0600

ahlyder gravatar image

I am trying to create a library package which also includes header files to include from another package, but the other package is not able to find them. The CMakelist.txt from the library package looks like this:

cmake_minimum_required(VERSION 3.5)

project(device_engine)

# 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(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)

include_directories(
  include
)

ament_export_dependencies(rosidl_default_runtime)

add_library(device_engine
  src/action.cpp
  src/resource.cpp
  src/device_engine.cpp
  src/event_log_object.cpp
  src/log_handler.cpp
  src/log_handler_cout.cpp
)

ament_target_dependencies(device_engine)

install(TARGETS
  device_engine
  DESTINATION lib/${PROJECT_NAME}
  PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}/
  )

install(DIRECTORY include/${PROJECT_NAME}/
  DESTINATION include/${PROJECT_NAME}
  FILES_MATCHING PATTERN "*.h"
  PATTERN ".git" EXCLUDE)

ament_package()

The header files are copied correctly to install/device_engine/include/device_engine/ but it seems that the variable ${device_engine_INCLUDE_DIRS} is empty when calling find_package(device_engine) from the other package including the header files with the following CMakelists.txt:

cmake_minimum_required(VERSION 3.5)

project(mac_gateway)

# 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(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(happtec_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(device_engine REQUIRED)

include_directories(
  include
  ${device_engine_INCLUDE_DIRS}
)

message(STATUS "Variables: ${device_engine_INCLUDE_DIRS}")

ament_export_dependencies(rosidl_default_runtime)

add_executable(mac_gateway
  src/resource_test_1.cpp
  src/main.cpp
)

target_link_libraries(mac_gateway device_engine)

ament_target_dependencies(mac_gateway device_engine rclcpp std_msgs std_srvs happtec_msgs)

install(TARGETS
  mac_gateway
  DESTINATION lib/${PROJECT_NAME})

ament_package()

The only error I get is that when compiling this, it is unable to find the header files. find_package(device_engine) does not produce any error.

What am I missing?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2018-10-17 11:50:48 -0600

jacobperron gravatar image

updated 2018-10-17 11:51:49 -0600

I think you need to tell ament about the header files. In the first CMake file, try adding ament_export_include_directories(include) before the line with ament_export_dependencies.

edit flag offensive delete link more

Comments

You're right - thank you! That, and removing the from target_link_libraries(mac_gateway device_engine) from the package using the include files fixed the issue.

ahlyder gravatar image ahlyder  ( 2018-10-18 03:22:22 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2018-10-15 01:09:24 -0600

Seen: 3,534 times

Last updated: Oct 17 '18