Include path for custom interface files in ROS2

Hi there,

I am currently using ROS2 Dashing for a small project. I have a workspace with two packages. In the one package I only have custom interface files (.msg). In the second package I have two nodes, a simple publisher and a subscriber. Those exchange the custom message defined in the other package. When compiling the packages with colcon there are no errors, but VS-Code can not find the header-file for the custom message. Because of that I always get include errors and intellisense does not work, which is very inconvenient. As far as I know, the headerfiles are generated dynamically so I have no idea to include those with VS-Code. Is there a way to make VS-Code include these custom messages?

edit retag close merge delete

Sort by » oldest newest most voted

Be sure you've installed the ros extension for one. Aside from this, if you open the ros_ws folder (i.e. the one which holds the install, build, and src folders) then it should configure itself automatically.

If it doesn't, open the .vscode/c_cpp_properties.json file and check that it contains the correct includePath (the most important for this being ${workspaceFolder}/** and /opt/ros/foxy/include/**). Mine for example: { "configurations": [ { "browse": { "databaseFilename": "", "limitSymbolsToIncludedHeaders": true }, "includePath": [ "${workspaceFolder}/**",
"/opt/ros/foxy/include/**",
"/usr/include/**"
],
"name": "ROS"
}
],
"version": 4
}


Again, for this to work vscode has to open in your ros_ws directory, such that it can walk through the install and src folders. Otherwise you can add them by manually backstepping in the include.

I've inspired my setup a bit by https://www.allisonthackston.com/articles/vscode-docker-ros2.html, she provides a docker for a vscode setup. I've taken some inspiration here regarding figuring out some of the slightly more obscure settings.

more

Hello there,

Have you tried configuring your compilers properties on VSCode (the c_cpp_properties.json file for example) by editing the IncludePath variable and adding the include file of your interfaces package (your_ros2_worspace_dir/install/your_interface_package_dir/include).

more

Hey there, did you ever figure out this issue? I'm also seeing this issue.

more