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

Extra subfolders in header include paths (and their impact on linting)

asked 2022-08-03 00:01:06 -0500

GoRobot gravatar image

I'm running Ubuntu 22.04, with kernel 5.15.0. I want to be able to run an automatic linter in the background on my C++ code for ROS2 in either Sublime Text (https://github.com/SublimeLinter/Subl...) or VS Code (https://code.visualstudio.com/docs/cp...). This requires me to configure my linter with the proper include paths to ROS2 headers (e.g., rclcpp.hpp).

Previously, with a binary installation of ROS2 Foxy on Ubuntu 20.04, I could do this by adding the folder /opt/ros/foxy/include to the -I option in SublimeLinter. Then, in my C++ file foo.cpp, I could write #include "rclcpp/rclcpp.hpp", and the linter would recognize the various objects in foo.cpp that came from this header file. However, now in ROS2 Humble on Ubuntu 22.04, all of these header files are located one folder deeper -- for example, rclcpp.hpp is located at /opt/ros/humble/include/rclcpp/rclcpp/rclcpp.hpp, where the extra folder named rclcpp is not a typo and only contains the single subfolder also named rclcpp. Now, to get correct linting when writing things like #include "rclcpp/rclcpp.hpp", I would need to manually include all of these subfolders rather than just the single subfolder /opt/ros/humble/include. It's not obvious to me why these extra subfolder levels are used in ROS2.

A similar problem occurs in linting when trying to include headers from other installed packages in a multi-package workspace. For example, consider the MWE at https://github.com/spenrich/ros2-exam... (based on the ROS2 tutorials). Building the packages in this workspace with ROS2 Rolling on Ubuntu 20.04 allows me to use the path $WORKSPACE_PATH/install/tutorial_interfaces/include in my linter settings to correctly handle when I write #include "tutorial_interfaces/msg/num.hpp". However, if I build using ROS2 Humble/Rolling on Ubuntu 22.04, I have to use the include path $WORKSPACE_PATH/install/tutorial_interfaces/include/tutorial_interfaces -- another instance of an extra sub-folder for no obvious reason.

TL;DR -- has anyone had success configuring their linter in Sublime Text (i.e., using https://github.com/SublimeLinter/Subl...) or VS Code (i.e., using https://code.visualstudio.com/docs/cp...) to work well with ROS2 Humble?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-08-17 19:40:02 -0500

tfoote gravatar image

The extra depth of the include paths are required to support proper isolation and ordering of includes.

The primary tracking ticket for this is https://github.com/ros2/ros2/issues/1150

It's likely that you want to configure your linter to ask colcon for the include path for your workspace instead of hard coding the paths.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-08-02 23:58:56 -0500

Seen: 38 times

Last updated: Aug 17 '22