I already build some others packages without errors, but now i'm trying to build a library now and i have this error: fatal error: rclcpp/rclcpp.hpp: No such file or directory 10 | #include "rclcpp/rclcpp.hpp".
I'm using ROS2 Humble on linux 22.04. In my .h file I #include "rclcpp/rclcpp.hpp". I source with this command source /opt/ros/humble/setup.bash
and in the same workspace I can build other packages individually.
Many thanks to all of you.
-Here my CMake file-
project(TEST_LIB)
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)
include_directories(include)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
add_library(TEST_LIB src/TEST_LIB.cpp)
# this line to export the library
ament_export_targets(TEST_LIB HAS_LIBRARY_TARGET)
# install the include/arto directory to the install/include/arto
#install (
# DIRECTORY include/TEST_LIB # This specifies the source directory that you want to install.This directory likely contains header files associated with the arto_lib library.
# DESTINATION include) # This specifies the destination directory where you want to install the source directory.
install (
TARGETS TEST_LIB # sto installando gli artefatti generatomi dal cmake di arto_lib, quelli definiti in add_library
EXPORT TEST_LIB # Export permette alla libreria arto_lib di essere esportata ed utilizzata da altri progetti, permettendogli di linkarsi
LIBRARY DESTINATION lib # This specifies the directory where the built shared libraries (if any) associated with the arto_lib target should be installed.
ARCHIVE DESTINATION lib # This specifies the directory where the built static libraries (if any) associated with the arto_lib target should be installed.
RUNTIME DESTINATION bin # This specifies the directory where any executable files generated by the arto_lib target should be installed. USLESS HERE
INCLUDES DESTINATION include # This specifies the directory where any public header files associated with the arto_lib target should be installed.
)
ament_package()
And here my package.xml
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>TEST_LIB</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">user</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>rclcpp</depend>
<depend>std_msgs</depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>