Including custom header file in ROS2 CMakeList
Hello everyone,
I'm trying to create a ROS2 package, which has a custom header file, and links to other header files downloaded from GitHub (in this case WiringPi).
For doing this, I understand that I must place my custom header file inside of the /include/package_name directory, but I cannot link it to the source file. I'm trying to following the documentation of ament_cmake for "Adding files and headers", "Adding dependencies" and "Building a Library". Honestly, I don't really understand the documentation very well, and the lack of examples are making it hard for me to implement it myself.
Could anyone assist me with understanding how I can link my header file to my source file (e.g. through a sample CMakeList/package.xml), and with adding e.g. the WiringPi to the code?
I'm currently following this post, and using the same files+filenames, but the source file still isn't able to find the header file.
Ubuntu 20.04, ROS2 Foxy, C++
Thank you in advance, for any insights that could lead to me overcoming my problem.
My CmakeList.txt
cmake_minimum_required(VERSION 3.5)
project(tester123)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# 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 dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
add_executable(main_node src/minimal_publisher_node.cpp src/minimal_publisher.cpp)
ament_target_dependencies(main_node rclcpp std_msgs)
install(TARGETS
main_node
DESTINATION lib/${PROJECT_NAME})
install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}/
)
install(
DIRECTORY include/
DESTINATION include
)
ament_package()
Error code (during colcon build)
tester123/src/minimal_publisher.cpp:1:10: fatal error: minimal_publisher.hpp: No such file or directory
1 | #include "minimal_publisher.hpp"