Ask Your Question
0

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

1 Answer

Sort by » oldest newest most voted
2

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 imageTristanNoctis ( 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 imagegvdhoorn ( 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 imagegvdhoorn ( 2019-01-12 07:53:21 -0600 )edit

Thanks for that

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 1,823 times

Last updated: Jan 11