optical_anathema
optical_anathema

Reputation: 146

Visual Studio Code IncludePath Issue with ROS headers

I'm getting squiggly lines under the statements of #include "rclcpp/rclcpp.hpp" from the ROS2 tutorial I'm going through and updating IncludePath in c_cpp_properties.json is not fixing the issue.

Here's what my c_cpp_properties file looks like:

{
    "configurations": [
        {
            "browse": {
                "databaseFilename": "",
                "limitSymbolsToIncludedHeaders": true
            },
            "includePath": [
                "/opt/ros/foxy/include/**",
                "/home/thomas/ws_ros2/src/cpp_pubsub/include/**",
                "/usr/include/**"
            ],
            "name": "ROS",
            "intelliSenseMode": "gcc-x64",
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++14",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}

The ROS extension recognizes that I'm working with a ROS package so my settings.json looks like this:

{
    "python.autoComplete.extraPaths": [
        "/home/thomas/ws_ros2/install/warehouse_ros_mongo/lib/python3.8/site-packages",
        "/home/thomas/ws_ros2/install/moveit_msgs/lib/python3.8/site-packages",
        "/opt/ros/foxy/lib/python3.8/site-packages"
    ],
    "C_Cpp.errorSquiggles": "Enabled"
}

But no matter what I do I can't seem to get rid of these squiggles.

enter image description here

Upvotes: 4

Views: 9332

Answers (4)

Roland Sarrazin
Roland Sarrazin

Reputation: 1345

I could achieve a stable IntelliSense experience with ROS2 by generating the compile commands:

colcon build --symlink-install --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

In this case, colcon generates a combined compile_commands.json in the build folder, so that the following c_cpp_properties.json file does the trick:

{
  "configurations": [
    {
      "name": "ROS",
      "compileCommands": "${workspaceFolder}/build/compile_commands.json",
      "intelliSenseMode": "gcc-x64",
      "compilerPath": "/usr/bin/gcc",
      "cStandard": "gnu11",
      "cppStandard": "c++14"
    }
  ],
  "version": 4
}

So far, the ROS extension hasn't overwritten the file, so that the IntelliSense experience is stable. Additionally, it looks like this combined file is also considered by clang-tidy.

Note that I also posted this answer in Robotics Stack Exchange, VSCode does not recognice RCLCPP_INFO.

Upvotes: 1

Mubashir
Mubashir

Reputation: 135

  1. Update the "includePath": [] configuration in your .vscode/c_cpp_properties.json file with the following:
            "includePath": [
                "${workspaceFolder}/**",
                "/opt/ros/noetic/include/**",
                "/usr/include/eigen3"
            ],
  1. Open your ros workspace with VScode directly code my_ros_ws. both work for me

Upvotes: 6

JRTG
JRTG

Reputation: 101

As a reference: I had the same issue but due to a different reason:

Turns out that in my case it was due to having multiple root folders in my workspace (through RMB and "Add Folder to Workspace...").

By copying the .vscode folder (with c_cpp_properties.json) to each of the root folders, it seems to be resolved.

Upvotes: 0

optical_anathema
optical_anathema

Reputation: 146

Removing configurationProvider from c_cpp_properties.json did the trick and intellisense is working now. enter image description here

Upvotes: 5

Related Questions