ament / ament_index

Apache License 2.0
13 stars 27 forks source link

ament_index_cpp header files may not be installed in the right place #84

Closed AndyZe closed 2 years ago

AndyZe commented 2 years ago

I'm probably doing something wrong, but figure I will raise the issue just in case.

/home/andy/.../task_planning/src/task_data_parser.cpp:5:10: fatal error: ament_index_cpp/get_package_share_directory.hpp: No such file or directory
    5 | #include "ament_index_cpp/get_package_share_directory.hpp"

I temporarily "fixed" this by copying all of the header files down one directory.

I do have ament_index_cpp listed in my package.xml and CMakeLists.

clalancette commented 2 years ago
  • ament_index_cpp header files are installed to /opt/ros/rolling/include/ament_index_cpp/ament_index_cpp

  • Previously, the same header filers were installed to /opt/ros/rolling/include/ament_index_cpp/

This is by design; see https://github.com/ros2/ros2/issues/1150 for a lot of information on why we did this.

So most likely the problem is that you are using "old-style" CMake variables when linking. Instead, you should be using either ament_target_dependencies(ament_index_cpp), or target_link_libraries(ament_index_cpp::ament_index_cpp). If you give us a pointer to your CMakeLists.txt, we can probably give you some advice on how to fix it.

AndyZe commented 2 years ago

Here are the relevant snippets of my CMakeLists. No luck so far.

...
set(THIS_PACKAGE_INCLUDE_DEPENDS
    ament_cmake
    ament_cmake_python
    ament_index_cpp
    control_msgs
    moveit_task_constructor_core
    moveit_task_constructor_msgs
    rclcpp
    yaml-cpp
)

find_package(ament_cmake REQUIRED)
find_package(fmt REQUIRED)

foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
  find_package(${Dependency} REQUIRED)
endforeach()

...

# This is the library where the build fails
add_library(task_data_parser
  src/task_data_parser.cpp
)
target_include_directories(task_data_parser PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>)
ament_target_dependencies(task_planning_cpp
  PUBLIC
    ${THIS_PACKAGE_INCLUDE_DEPENDS}
)
target_link_libraries(task_planning_cpp
  PRIVATE
    ament_index_cpp::ament_index_cpp
    ${YAML_CPP_LIBRARIES}
)
AndyZe commented 2 years ago

Oh, it was a stupid typo. I had the wrong package name in target_link_libraries. I also needed the ament_index_cpp::ament_index_cpp

Thanks.