Robotics StackExchange | Archived questions

Unable to find header from another package ros2

Project canbus -> adds a library and i see the header files in the install directory, heres the cmake:

cmake_minimum_required(VERSION 3.10)
project(canbus)
set(CMAKE_CXX_STANDARD 14)

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

find_package(ament_cmake_auto REQUIRED)
find_package(Threads)

include_directories(
    include
)

ament_export_include_directories(include)

add_library(canbus 
    src/canbus.cpp
)
ament_target_dependencies(canbus)

install(TARGETS
  canbus
  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()

Package 2 imu_driver cmake:

cmake_minimum_required(VERSION 3.10)
project(imu_driver)

# 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(canbus REQUIRED)

include_directories(
  include
  ${canbus_INCLUDE_DIRS}
)

add_executable(imu_driver
    src/imu_driver.cpp
)

ament_target_dependencies(imu_driver canbus)

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

ament_package()

It's able to find the package canbus but the header file is not found.

Asked by pbaj on 2021-08-05 11:47:05 UTC

Comments

What's the output when you run (in your workspace root directory):

ls -R install/canbus/include/

Do the header files exist in there? If it doesn't, its a problem with canbus' cmake. Otherwise it's a problem with imu_driver's cmake.

Asked by ijnek on 2021-08-05 18:32:51 UTC

Answers