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

Error in vscode: "ros/ros.h"- No such file or directory

asked 2022-06-11 13:31:40 -0600

helloros gravatar image

updated 2022-06-11 13:32:44 -0600

Hi all, i am new in ROS and am trying to setup my vscode environment for ROS. I searched a lot for the right answer but could not solve my problem. I inlcuded all important lines in my CMakeList but the error is still not gone, so i am clearly missing something. I am using melodic 1.14.10 on Ubuntu.

Here is my CMakeList:

cmake_minimum_required(VERSION 3.0.2)
project(hello)


find_package(catkin REQUIRED COMPONENTS
  nav_msgs
  roscpp
  rospy
  sensor_msgs
  std_msgs
  geometry_msgs
  message_filters 
)


catkin_package(
  INCLUDE_DIRS include
  LIBRARIES hello
  CATKIN_DEPENDS nav_msgs roscpp rospy sensor_msgs std_msgs geometry_msgs message_filters
  DEPENDS system_lib
)


include_directories(
  #include/hello
  ${catkin_INCLUDE_DIRS}
)

add_library(${PROJECT_NAME}
   src/ekf.cpp
)

## add_executable(EKF src/main.cpp)
add_executable(EKF src/main.cpp src/ekf.cpp)

target_link_libraries(EKF ${catkin_LIBRARIES})

My tasks.json:

{
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: cpp Aktive Datei kompilieren",
            "command": "/usr/bin/cpp",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Vom Debugger generierte Aufgabe."
        }
    ],
    "version": "2.0.0"
}

My simple header file with the #include ros/ros.h causing the problem:

#include <ros/ros.h>
#include <std_msgs/String.h>
#include <sensor_msgs/LaserScan.h>
#include <nav_msgs/Odometry.h>
#include "tf/tf.h"
#include <geometry_msgs/Twist.h>

#include <fstream>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

class EKF{
    public:

        vector<double> landmarks;
        int count;

        vector<double> readFile(ros::NodeHandle nh);

};

I could not attach a screenshot to show the error, but it says exactly the this line:

"ros/ros.h"- No such file or directory

I really appreciate your support.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2022-06-12 13:45:52 -0600

helloros gravatar image

Thank you for your response!

I have created my workspace from scratch and added your .vscode/c_cpp_properties.json and .vscode/settings.json but nothing has changed on the ros/ros.h error.

Now it looks like this:

{
  "configurations": [
    {
      "browse": {
        "databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db",
        "limitSymbolsToIncludedHeaders": false
      },
      "includePath": [
        "/opt/ros/melodic/include/**",
        "/home/kubra/catkin_ws/src/mus1/include/**",
        "/usr/include/**"
      ],
      "name": "ROS",
      "intelliSenseMode": "gcc-x64",
      "compilerPath": "/usr/bin/gcc",
      "cStandard": "gnu11",
      "cppStandard": "c++14"
    }
  ],
  "version": 4
}

And my settings.json:

{
    "editor.tabSize": 4,
    "ros.distro": "melodic",
    "ros.rosSetupScript": "/opt/ros/noetic/setup.bash",

    "python.autoComplete.extraPaths": [
        "/opt/ros/melodic/lib/python2.7/dist-packages"
    ],
    }

But still he error is showing up. What else can i do to make the error dissappear?

edit flag offensive delete link more

Comments

"ros.rosSetupScript": "/opt/ros/noetic/setup.bash",

Since you're using melodic, change noetic to melodic.

Also, vscode gives you one of the lightbulbs if it detects an error. If you click that, does it give you a solution? Sometimes if your include path is close enough but not perfect, it realizes what you're trying to do and gives you the option to have vscode fix it.

Joe28965 gravatar image Joe28965  ( 2022-06-13 05:18:59 -0600 )edit
0

answered 2022-06-11 16:08:44 -0600

aarsh_t gravatar image

In your .vscode/c_cpp_properties.json

{
"configurations": [
    {
        "name": "Linux",
        "includePath": [
            "${workspaceFolder}/**",
            "/opt/ros/noetic/include"
        ],
        "defines": [],
        "compilerPath": "/usr/bin/gcc",
        "cStandard": "gnu11",
        "cppStandard": "c++11",
        "intelliSenseMode": "linux-gcc-x64"
    }
],
"version": 4
}

in your .vscode/settings.json for autocomplete python

{
"editor.tabSize": 4,
"ros.distro": "noetic",
"ros.rosSetupScript": "/opt/ros/noetic/setup.bash",

"python.autoComplete.extraPaths": [
    "/opt/ros/noetic/lib/python3/dist-packages"
],
}
edit flag offensive delete link more
0

answered 2023-07-31 20:10:50 -0600

JohnDoe gravatar image

updated 2023-08-01 03:02:23 -0600

For the code snippet in the task.json:

"args": [
             "-g",
             "${file}",
              "-o",
              "${fileDirname}/${fileBasenameNoExtension}"
          ],

g++ doesn't build your source file with -I option, which means the ROS header is not included.

You can create a new task with

    {
        "type": "shell",
        "command": "catkin build",
        "problemMatcher": [],
        "label": "catkin build",
    },

This will save a lot of trouble with constructing g++ options and build directly from CMakeList.txt.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-06-11 13:31:40 -0600

Seen: 2,692 times

Last updated: Aug 01 '23