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

ros/ros.h No such file or directory

asked 2019-01-11 08:13:18 -0600

TristanNoctis gravatar image

I have been running ROS Melodic in my Ubuntu Bionic system. I already had a previous workspace called 'catkin_ws'. Recently, I tried to create another workspace which I named 'ros'. I then created a directory called 'first_package' inside the 'src' folder using the 'catkin_create_pkg' command. I then coded a small segment which I have attached below and named it hello.cpp inside the 'first_package' which I have attached below.

//This is the ROS standard of "hello, world" program//

//This header defined standard ROS classed//
#include<ros/ros.h>

int main(int argc, char **argv){
//Initialize the ROS system
ros::init(argc, argv, "hello_ros");

//Establish this program as ROS node
ros::NodeHandle nh;

//Send some output as log message
ROS_INFO_STREAM("Hello, ROS!");
}

I have changed both the CMakeLists.txt and Package.xml accordingly, but I still receive this error. Could someone please resolve this issue. The error occurs when I use the command 'catkin_make'

This is the CMakeLists.txt file

cmake_minimum_required(VERSION 2.8.3)
project(first_package)
find_package(catkin REQUIRED COMPONENTS roscpp)
catkin_package()
include_directories()
add_executable(hello hello.cpp)
target_link_libraries(hello ${catkin_LIBRARIES})

The package.xml file is as follows,

<?xml version="1.0"?>
<package format="2">
  <name>first_package</name>
  <version>0.0.0</version>
  <description>The first_package package</description>
<maintainer email="danish@todo.todo">danish</maintainer>


 <license>TODO</license>
      <buildtool_depend>catkin</buildtool_depend>
      <build_depend>roscpp</build_depend>
      <exec_depend>roscpp</exec_depend>

<export>
  </export>
</package>
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2019-01-11 15:16:23 -0600

gvdhoorn gravatar image

updated 2019-01-11 15:16:57 -0600

include_directories()

This is most likely your problem.

Even though you first do this:

find_package(catkin REQUIRED COMPONENTS roscpp)

You never update the include path with the contents of catkin_INCLUDE_DIRS, causing the compiler (or actually: the preprocessor) to not be able to find the headers.

You'll need to change that statement to at least something like the following:

include_directories(${catkin_INCLUDE_DIRS})

Note that this is not really a ROS issue, but a CMake one.

edit flag offensive delete link more

Comments

You solved the issue! Can you be more precise as to why that part was needed to be added inside the include_directories()?

TristanNoctis gravatar image TristanNoctis  ( 2019-01-12 06:39:01 -0600 )edit

See the CMake documentation: include_directories().

As to why include directories need to be setup, that would be a generic programming question.

As to what catkin_INCLUDE_DIRS is: see the general Catkin documentation on ..

gvdhoorn gravatar image gvdhoorn  ( 2019-01-12 07:52:32 -0600 )edit

.. the ROS wiki here and the Include Paths and Library Paths section in particular.

Use ctrl+f and search for catkin_INCLUDE_DIRS on that page.

gvdhoorn gravatar image gvdhoorn  ( 2019-01-12 07:53:21 -0600 )edit

Thanks for that

TristanNoctis gravatar image TristanNoctis  ( 2019-01-12 08:35:02 -0600 )edit
0

answered 2021-11-11 10:32:26 -0600

Kevin1719 gravatar image

When you need to build a node which created by a cpp file, your CMake file should look like this:

cmake_minimum_required(VERSION 3.0.2) 
Project(package_name) 

# if there is another "No such file or directory" error
# you may want to add that missing library like rospy, std_msgs, e.g. 
find_package(catkin REQUIRED COMPONENTS roscpp) 

catkin_package( 
#  INCLUDE_DIRS include 
#  LIBRARIES motion_plan 
#  CATKIN_DEPENDS other_catkin_pkg 
#  DEPENDS system_lib 
) 

include_directories(include ${catkin_INCLUDE_DIRS}) 

add_executable(node_name src/file_name.cpp) 
target_link_libraries(node_name ${catkin_LIBRARIES})

I was stuck with this erro and then this worked for me.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-01-11 08:13:18 -0600

Seen: 9,053 times

Last updated: Nov 11 '21