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

fatal error: ros/ros.h: No such file or directory

asked 2016-06-20 02:33:34 -0500

updated 2016-06-21 07:01:52 -0500

I have created a package using catkin_create_pkg on my raspberry pi 3 where I have previously installed Ubuntu Xenial and ROS kinetic. But everytime I am trying to compile the cpp file included in the created package I get the following error

fatal error: ros/ros.h: No such file or directory
compilation terminated.

looks like it does not see any of the header files included in my cpp file.

I have all set up the same way on my other computer running ubuntu Trusty and ROS indigo. Not sure why this is happening here.

Edit: This is what I added to my package.xml

  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>geometry_msgs</build_depend>
  <build_depend>message_generation</build_depend>

  <run_depend>roscpp</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>std_msgs</run_depend>
  <run_depend>geometry_msgs</run_depend>
  <run_depend>message_runtime</run_depend>

here is the Cmakelist.txt:

cmake_minimum_required(VERSION 2.8.3)
project(sphero_move)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED)

include_directories(${catkin_INCLUDE_DIRS})

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
find_package(catkin REQUIRED COMPONENTS 
  roscpp
  rospy
  std_msgs
  geometry_msgs
  message_generation
)

## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend tag for "message_generation"
##   * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependency has been pulled in
##     but can be declared for certainty nonetheless:
##     * add a run_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )

## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )

## Generate added messages and services with any dependencies listed here
# generate_messages(
#   DEPENDENCIES
#   std_msgs  # Or other packages containing msgs
# )

################################################
## Declare ROS dynamic reconfigure parameters ##
################################################

## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
##   * add a build_depend and a run_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
##   * add "dynamic_reconfigure" to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * uncomment the "generate_dynamic_reconfigure_options" section below
##     and list every .cfg file to be processed

## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
#   cfg/DynReconf1.cfg
#   cfg/DynReconf2 ...
(more)
edit retag flag offensive close merge delete

Comments

Without seeing at least your CMakeLists.txt and package.xml this is going to be difficult to diagnose. Please include a copy of those files (without all the boilerplate comments) in your question. Use the edit button/link for that, and the Preformatted text button to format them.

gvdhoorn gravatar image gvdhoorn  ( 2016-06-20 02:58:29 -0500 )edit
3

I don't see a include_directories(${catkin_INCLUDE_DIRS}) anywhere in your snippet (is that the whole file?). Without that, any #include .. of ROS related files will fail with the error you mentioned.

gvdhoorn gravatar image gvdhoorn  ( 2016-06-20 04:08:57 -0500 )edit

right, that idea that gvdhoorn says looks good

Pablo Iñigo Blasco gravatar image Pablo Iñigo Blasco  ( 2016-06-20 06:00:42 -0500 )edit

Just included it and edited the question above with the full content of my CMakeLists.txt file. No success so far

aldolereste gravatar image aldolereste  ( 2016-06-21 07:05:15 -0500 )edit
2

For future questions: please don't include all the comments whenever you post a CMakeLists.txt: they are completely unnecessary, and make it harder to spot problems.

gvdhoorn gravatar image gvdhoorn  ( 2016-06-21 08:27:19 -0500 )edit

4 Answers

Sort by » oldest newest most voted
15

answered 2016-06-21 08:35:36 -0500

gvdhoorn gravatar image

From your CMakeLists.txt this appears to be more of a CMake problem than really ROS related, but:

cmake_minimum_required(VERSION 2.8.3)
project(sphero_move)

...

find_package(catkin REQUIRED)

include_directories(${catkin_INCLUDE_DIRS})

find_package(catkin REQUIRED COMPONENTS 
  ...
)

This is your problem: you find_package(..) the catkin package twice. As with other CMake libraries, the second will not necessarily overwrite the first, so it never really does what you want.

Apart from that, you invoke include_directories(..) before your call to find_package(catkin ..) which actually finds the ROS packages you are interested in, and are using. At that point, catkin_INCLUDE_DIRS is empty, leading to no changes to the header search path and ultimately the errors you see.

I'd suggest to merge the two find_package(catkin ..) calls, keep the COMPONENTS and its arguments, and place the include_directories(..) line after find_package(catkin ..) has had a chance to find your dependencies and populate the variable.

Some references: catkin/CMakeLists.txt on the ROS wiki, and catkin 0.6.18 documentation » How to do common tasks » Package format 2 (recommended) in the Catkin docs (Indigo version). For the second link, see the C++ catkin library dependencies and C++ system library dependencies sections.

edit flag offensive delete link more

Comments

That worked. Thanks

aldolereste gravatar image aldolereste  ( 2016-06-23 05:02:58 -0500 )edit

i have the same issue but my CMakeLists seems fine. i am using ros noetic

Ahmed Ayman gravatar image Ahmed Ayman  ( 2021-04-19 09:52:46 -0500 )edit
4

answered 2017-06-01 14:55:43 -0500

lucasw gravatar image

I had this error with a package that compiled fine in Jade but not Kinetic, it turned out I had spelled catkin_INCLUDE_DIRS wrong. I think pre-Kinetic includes from every package in a workspace were commingled (so the correctly spelled included in a previously processed package got the includes in).

edit flag offensive delete link more
1

answered 2017-07-06 07:48:31 -0500

cydonia gravatar image

updated 2017-07-06 08:10:49 -0500

Using Ubuntu Xenial and Kinetic Kame, I'm going through the tutorials and right now I'm at "Writing Service&Client" part. When I tried to catkin_make the project, I got the same problem, however none of the above mentioned solutions worked for me. Here is my CMakeList.txt:

cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)

find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg)

add_message_files(FILES Num.msg)
add_service_files(FILES AddTwoInts.srv)

generate_messages(DEPENDENCIES std_msgs)

catkin_package()
include_directories(include ${catkin_INCLUDE_DIRS})

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

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

add_executable(add_two_ints_server src/add_two_ints_server.cpp)
target_link_libraries(add_two_ints_server ${catkin_LIBRARIES})
add_dependencies(add_two_ints_server beginner_tutorials_gencpp)

add_executable(add_two_ints_client src/add_two_ints_client.cpp)
target_link_libraries(add_two_ints_client ${catkin_LIBRARIES})
add_dependencies(add_two_ints_client beginner_tutorials_gencpp)

Nothing seems wrong to me (in fact the file is exactly this, without the comments), however I may be missing something.

edit flag offensive delete link more
0

answered 2016-07-21 15:50:57 -0500

waffaw69 gravatar image

updated 2016-07-21 17:38:22 -0500

Hi, I have the same problem but my CMakeLists.txt and package.xml seem good. First I thought it was a problem with the new version of ROS Kinetic but it is not, as my other packages compile and work well. I am using Ubuntu 16.04 with ROS Kinetic. Here is my error :

.../catkin_ws/src/stereocamera/src/stereocamera.cpp:1:21: fatal error: ros/ros.h: No such file or directory

The header in my stereocamera.cpp file is #include<ros/ros.h>. This is my CMakeLists.txt :

cmake_minimum_required(VERSION 2.8.3)
project(stereo_camera)

find_package(catkin REQUIRED COMPONENTS roscpp std_msgs sensor_msgs cv_bridge image_transport compressed_image_transport)
find_package(OpenCV REQUIRED)

catkin_package()

add_executable(stereocamera src/stereocamera.cpp)
target_link_libraries(stereocamera ${catkin_LIBRARIES} ${OpenCV_LIBS})

And my package.xml :

<?xml version="1.0"?>
<package>
  <name>stereo_camera</name>
  <author>Me</author>
  <maintainer email="you@yourdomain.tld">Me</maintainer>
  <description>Stereo camera package</description>
  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>sensor_msgs</build_depend>
  <build_depend>OpenCV</build_depend>
  <build_depend>cv_bridge</build_depend>
  <build_depend>image_transport</build_depend>
  <build_depend>compressed_image_transport</build_depend>
  <run_depend>roscpp</run_depend>
  <run_depend>std_msgs</run_depend>
  <run_depend>sensor_msgs</run_depend>
  <run_depend>OpenCV</run_depend>
  <run_depend>cv_bridge</run_depend>
  <run_depend>image_transport</run_depend>
  <run_depend>compressed_image_transport</run_depend>
</package>

Do you have any idea to fix the problem ?

Note that the package runs well on Ubuntu 14.04 with ROS Jade.

edit flag offensive delete link more

Comments

7

I found the solution, I added include_directories(${catkin_INCLUDE_DIRS}) after catkin_package(). That's weird that it works on ROS Jade without the include_directories but not on ROS Kinetic...

waffaw69 gravatar image waffaw69  ( 2016-07-21 17:46:04 -0500 )edit

Yes, for Kinetic include_directories() is necessary.

dolphinlove gravatar image dolphinlove  ( 2018-07-12 01:41:59 -0500 )edit

include_directories(${catkin_INCLUDE_DIRS}) works for me on ROS Melodic

askkvn gravatar image askkvn  ( 2021-04-22 02:12:48 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-20 02:33:34 -0500

Seen: 93,368 times

Last updated: Jul 06 '17