ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
The ROS extension mentioned in wiki/IDEs includes a task to update the c_cpp_properties.json
(adding ROS paths to includePath
), but in my experience that feature is brittle.
It is much more robust to let catkin handle that by getting CMake to export compile_commands.json
during the build process. Then you can point C++ IntelliSense to that compile_commands.json
as an alternative to modifying the includePath
. VSCode reference
More details (copied from my here):
This blog post by Erdal gives nice step-by-step instructions.
I had to make one change, though: Instead of creating the new catkin_make
task, I used the default catkin: make
task that the VSCode ROS extension automatically creates.
For IntelliSense to work, CMake in the catkin: make
task needs to be configured to generate compile_commands.json
, as the blog mentions. But the catkin: make
task command cannot be edited. However, it simply runs catkin build
(or catkin_make
, whichever command you normally use to build ROS workspaces) under the hood. So I pre-configure catkin for my ROS workspace like so:
bash
$ cd catkin_ws
$ catkin config -a --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=1
Note that I use catkin-tools
, not the simple catkin
that ships with ROS.
The above command caches the CMAKE_EXPORT_COMPILE_COMMANDS
CMake argument in the catkin configuration. As mentioned in the blog, this CMake argument causes it to create compile_commands.json
in catkin_ws/build/<package_name>/
. If you point IntelliSense to this file using the compileCommands
field in c_cpp_properties.json
as mentioned in the blog, everything works.