ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

how to include library header files

asked 2020-10-28 03:03:59 -0600

stewart menday gravatar image


I am new to colcon and ros in general, so please forgive my newby question. I completed the all the beginner ROS2 tutorials and all went well.

Now I am trying to compile some third party code into a library (feetech_driver) to use in another ROS package (ft_joint). I have been able to compile the library and the output files are copied to


All the header files are in the ros_ws/install/feetech_driver/include/feetech_driver directory

My other ROS package (ft_joint) that is trying to use this library package cannot find the required header file, I am including it like so,

#include "feetech_driver/SCSCL.h"

As part of my ft_joint package I also include files from the tutorial_interfaces tutorial and I can include those without error, like so,

#include "tutorial_interfaces/msg/num.hpp"

My CMakeList.txt has a find_package for both packages, like so

find_package(tutorial_interfaces REQUIRED)
find_package(feetech_driver REQUIRED)

The error that I get when I run

colcon build --packages-select ft_joint


/home/stewart/ros/dev_ws/src/ft_joint/src/joint_node.cpp:6:10: fatal error: feetech_driver/SCSCL.h: No such file or directory
    6 | #include "feetech_driver/SCSCL.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~

Any suggestions would be greatly appreciated.

Thanks Stew

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-10-29 12:27:16 -0600

ahcorde gravatar image


In this repo you will find some basic ROS 2 examples. For example you should have a look to this CMakeLists.txt.

You should find_package:

find_package(rclcpp REQUIRED)

And then if it's a ROS 2 dependency, you should link against it

ament_target_dependencies(<you target name> rclcpp )

If it's not a ROS 2 dependency, then you should use the CMake functions. Like target_link_libraries or target_include_directories.


edit flag offensive delete link more


Thank you for your answer. I have been able to get it to work as follows, In my CMakeList.txt file I originally had

find_package(feetech_driver REQUIRED)

add_executable(joint_node src/joint_node.cpp)
ament_target_dependencies(joint_node rclcpp tutorial_interfaces feetech_driver ft_message)

Which didn't work, it wouldn't find the headers or the feetech_driver library file. After changing CMakeList.txt to

find_package(feetech_driver REQUIRED)
#don't know why the find_package(feetech_driver REQUIRED) above isn't sufficient, but need the 2 lines below
find_library(DRIVER ftd_scscl)
add_executable(joint_node src/joint_node.cpp)
ament_target_dependencies(joint_node rclcpp tutorial_interfaces feetech_driver ft_message)
target_include_directories(joint_node PUBLIC $<BUILD_INTERFACE:${HEADERS}>)
target_link_libraries(joint_node ${DRIVER})

It now works :)

stewart menday gravatar image stewart menday  ( 2020-10-29 19:51:51 -0600 )edit

Question Tools



Asked: 2020-10-28 03:03:59 -0600

Seen: 4,491 times

Last updated: Oct 29 '20