Ask Your Question
0

how to include library header files

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

stewart menday gravatar image

Hi

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

ros_ws/install/feetech_driver
      |-include
      |-lib
      |-share

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

is

/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
2

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

ahcorde gravatar image

Hello,

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.

Regards

edit flag offensive delete link more

Comments

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)
find_path(HEADERS NAMES SCSCL.h SCSerial.h SCServo.h SCS.h HINTS ${AMENT_PREFIX_PATH})
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 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 1,855 times

Last updated: Oct 29 '20