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

ros/ros.h: No such file or directory

asked 2021-09-15 09:02:46 -0500

lzyr gravatar image

updated 2021-09-16 03:48:54 -0500

Hello, I'm new to ROS, and I have some trouble with my first file. When I include: #include "ros/ros.h" in VSCode, it says "ros/ros.h: No such file or directoy". I'm using ROS Melodic on Ubuntu 18.04.

Here is my CMakeLists.text:

cmake_minimum_required(VERSION 3.0.2)
project(helloworld)
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)
catkin_package()
include_directories(
  ${catkin_INCLUDE_DIRS}
)
add_executable(hello src/helloworld.cpp)
target_link_libraries(hello ${catkin_LIBRARIES})

Package.xml:

<?xml version="1.0"?>
<package format="2">
<name>helloworld</name>
<version>0.0.0</version>
<description>The helloworld package</description>
<maintainer email="dell@todo.todo">dell</maintainer>
<license>TODO</license>

 <buildtool_depend>catkin</buildtool_depend>
 <build_depend>roscpp</build_depend>
 <build_depend>rospy</build_depend>
 <build_depend>std_msgs</build_depend>

 <build_export_depend>roscpp</build_export_depend>
 <build_export_depend>rospy</build_export_depend>
 <build_export_depend>std_msgs</build_export_depend>
 <exec_depend>roscpp</exec_depend>
 <exec_depend>rospy</exec_depend>
 <exec_depend>std_msgs</exec_depend>

 <export>
 <!-- Other tools can request additional information be placed here -->
 </export>
 </package>

C_cpp.properities.json:

  {

"configurations": [
    {
        "browse": {
            "databaseFilename": "",
            "limitSymbolsToIncludedHeaders": true,
            "path": [
             "/opt/ros/melodic/include",
             "/usr/include"
        ]
    },
    "includePath": [
                "/opt/ros/melodic/include/**",
                "/usr/include/**",
                "/opt/ros/melodic/include"
            ],
            "name": "ROS",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64",
            "compilerPath": "/usr/bin/gcc"
        }
    ],
    "version": 4
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "catkin_make:debug",
            "type":"shell",
            "command":"catkin_make",
            "args": [
                "-I", "/opt/ros/melodic/include",
                "-I", "${workspaceFolder}"
             ],
            "group": {
            "kind": "build",
            "isDefault": true
             },
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "shared",
        "showReuseMessage": true,
        "clear": false
    },
    "problemMatcher":"$msCompile"
        }
    ]
}

And I have found "ros" directory using cd /opt/ros/melodic/include and ls. I'm quite confused now. Thanks for your help.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2021-09-15 18:16:10 -0500

Mike Scheutzow gravatar image

Did you try putting vscode in the search box at the top of this page?

There is a #q256565 "How to add ROS to path in VS Code?" on the first page of results.

edit flag offensive delete link more

Comments

Yeah, I followed these posts and set my C_cpp.properities.json and tasks.json. Still, this error arises.

lzyr gravatar image lzyr  ( 2021-09-15 21:35:53 -0500 )edit
0

answered 2021-09-16 01:59:26 -0500

Ranjit Kathiriya gravatar image

updated 2021-09-17 03:51:22 -0500

I think You forgot to include your workspace path, in c_cpp_properties For more ref: have a look at this answer, CPP solution is given #q382798

"~/<work-space>/devel/include"
edit flag offensive delete link more

Comments

I add this line in both c_cpp_propertities.json and tasks.json, but there is the same error.

lzyr gravatar image lzyr  ( 2021-09-16 03:46:06 -0500 )edit

When I include: #include "ros/ros.h" in VSCode,

Can you please try to run the program via the terminal? Does it work fine?

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-09-16 03:49:46 -0500 )edit

Can you please confirm that you have included path in this section in c_cpp_properties -> includePath ?

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-09-16 03:54:31 -0500 )edit

Yeah, I add the line: "/home/dell/catkin_ws/src/**" to c_cpp_properties in "includePath", but this error happens again. The program works fine via the terminal, though.

lzyr gravatar image lzyr  ( 2021-09-17 03:20:04 -0500 )edit

Ohhh! I am sorry,

"~/<work-space>/devel/include"

Open your devel folder and find the include folder you will solve this.

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-09-17 03:25:34 -0500 )edit

Do you mean adding the line "${workspaceFolder}/devel/include/**" ? In fact, I don't have a "include" directory in /devel.

lzyr gravatar image lzyr  ( 2021-09-17 03:39:34 -0500 )edit

Yes, but No. $ and {} things, for example, my workspace name is ws_ros.

"~/ws_ros/devel/include" - Directly,

One more thing to note you have to give include path only so no /**, You can also have a look by opening your workspace/devel folder where the include folder is you just have to add that path in c_cpp_propertities.json.

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-09-17 03:50:33 -0500 )edit

Unfortunately, it fails to work. I guess the point is, how vscode include header files from a third library.

lzyr gravatar image lzyr  ( 2021-09-18 03:55:07 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-09-15 09:02:46 -0500

Seen: 1,516 times

Last updated: Sep 17 '21