ROS2: error trying to include library in another package
Hi there, I am trying to create and export a library in a ROS2 package (named uwrt_mars_rover_hw_bridge
) and then use this library in another ROS2 package (named uwrt_mars_rover_utilities
) in the same workspace. However, I get a "no such file or directory" error when attempting to include header files from the library in the consumer package. I was hoping someone would be able to spot the error in my code that is causing this issue. One potential problem is that the library I am attempting to export has multiple include directories, and I would not like to change this fact as I am not the author of that code. Please let me know if you require more information about the structure of the packages.
Here is the CMakeLists.txt that is creating and exporting the library (uwrt_mars_rover_hw_bridge
package):
cmake_minimum_required(VERSION 3.8)
project(uwrt_mars_rover_hw_bridge)
if ("$ENV{TARGET}" MATCHES "2021$")
set(YEAR 2021)
elseif ("ENV{TARGET}" MATCHES "2022$")
set(YEAR 2022)
else ()
set(YEAR 2021) # default year to 2021
endif ()
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
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(rclcpp_components REQUIRED)
include_directories(
include
include/uwrt_mars_rover_utils
can
can/generated_${YEAR}
)
add_library(${PROJECT_NAME}_lib SHARED
src/hw_bridge.cpp
can/CANMsgMap.cpp
can/generated_${YEAR}/uwrt_mars_rover_can_wrapper.cpp
can/generated_${YEAR}/uwrt_mars_rover_can.c
)
ament_export_targets(${PROJECT_NAME}_lib HAS_LIBRARY_TARGET)
# Install the include directories: can, can/generated_${YEAR}, include,
include/uwrt_mars_rover_utils
install(
DIRECTORY can can/generated_${YEAR} include include/uwrt_mars_rover_utils
DESTINATION include
)
install(TARGETS ${PROJECT_NAME}_lib
EXPORT ${PROJECT_NAME}_lib
RUNTIME DESTINATION lib
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
INCLUDES DESTINATION include
)
ament_package()
Here is the CMakeLists.txt that is consuming the library (uwrt_mars_rover_utilities
package):
cmake_minimum_required(VERSION 3.8)
project(uwrt_mars_rover_utilities)
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
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(rclcpp_components REQUIRED)
find_package(std_msgs REQUIRED)
find_package(uwrt_mars_rover_hw_bridge REQUIRED)
include_directories(include)
add_library(${PROJECT_NAME} SHARED
src/uwrt_can.cpp
#src/uwrt_params.cpp
)
ament_target_dependencies(${PROJECT_NAME}
rclcpp
std_msgs
rclcpp_components
uwrt_mars_rover_hw_bridge
)
target_link_libraries(${PROJECT_NAME}
uwrt_mars_rover_hw_bridge::uwrt_mars_rover_hw_bridge_lib
)
install(TARGETS
${PROJECT_NAME}
RUNTIME DESTINATION lib/${PROJECT_NAME}
ARCHIVE DESTINATION lib/${PROJECT_NAME}
LIBRARY DESTINATION lib/${PROJECT_NAME}
)
ament_export_include_directories(
include
)
ament_export_dependencies(
rclcpp
)
ament_package()
And finally, here is the error message I am recieving (I have verified that this file should exist and the file is correct):
Starting >>> uwrt_mars_rover_utilities
--- stderr: uwrt_mars_rover_utilities
In file included from /home/username/uwrt_ws/src/uwrt_mars_rover/uwrt_mars_rover_utilities/src/uwrt_can.cpp:4:
/home/username/uwrt_ws/src/uwrt_mars_rover/uwrt_mars_rover_utilities/include/uwrt_mars_rover_utilities/uwrt_can.h:15:10: fatal error: uwrt_mars_rover_hw_bridge/can/CANMsgMap.h: No such file or directory
15 | #include "uwrt_mars_rover_hw_bridge/can/CANMsgMap.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/uwrt_mars_rover_utilities.dir/build.make:63: CMakeFiles/uwrt_mars_rover_utilities.dir/src/uwrt_can.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:107: CMakeFiles/uwrt_mars_rover_utilities.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed <<< uwrt_mars_rover_utilities [0.55s, exited with code 2]
Summary: 38 packages finished [7.59s]
1 package failed: uwrt_mars_rover_utilities
1 package had stderr output: uwrt_mars_rover_utilities
Asked by cwt1078 on 2023-02-02 16:39:20 UTC
Comments