Robotics StackExchange | Archived questions

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

Working Environment: Ubuntu 18.04 LTS; ROS Melodic.

Hi there, I am running through the TF tutorials on wiki.ros.org, I have simply followed the content of that tutorial. But unfortunately when I try to run the c++ code, there comes an error:

tf_broadcaster.cpp:1:10: fatal error: ros/ros.h: No such file or directory
 #include <ros/ros.h>
          ^~~~~~~~~~~
compilation terminated.

I have also tried to find out the answer from the others whose error are the same to mine. But their solutions didn't work with mine. I will post the CMakeLists and Package file as below(for your guys convinience, I have got rid of the content in comment) :

Thank you for your support!

By the way, the links, that I have looked for to find out the solution, will be posted as below:

link text link text link text link text

CMakeList.txt:

cmake_minimum_required(VERSION 2.8.3)
project(robot_setup_tf)

## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
    geometry_msgs
    roscpp
    tf
)

catkin_package(
    #INCLUDE_DIRS include
    #LIBRARIES robot_setup_tf
    #CATKIN_DEPENDS geometry_msgs roscpp tf
    #DEPENDS system_lib
)

include_directories(
# include
    ${catkin_INCLUDE_DIRS}
)

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

Package.xml:

<?xml version="1.0"?>
<package format="2">
    <name>robot_setup_tf</name>
    <version>0.0.0</version>
    <description>The robot_setup_tf package</description>
    <maintainer email="zhiwei@todo.todo">zhiwei</maintainer>
    <license>TODO</license>
    <buildtool_depend>catkin</buildtool_depend>
    <build_depend>geometry_msgs</build_depend>
    <build_depend>roscpp</build_depend>
    <build_depend>tf</build_depend>
    <build_export_depend>geometry_msgs</build_export_depend>
    <build_export_depend>roscpp</build_export_depend>
    <build_export_depend>tf</build_export_depend>
    <exec_depend>geometry_msgs</exec_depend>
    <exec_depend>roscpp</exec_depend>
    <exec_depend>tf</exec_depend>
    <export>
    </export>
</package>

Asked by ballaholic on 2019-05-29 16:01:05 UTC

Comments

I have also tried to find out the answer from the others whose error are the same to mine. But their solutions didn't work with mine.

Can you please update your question with links to the questions that you're referring to and what happened when you attempted the solutions? This way, people don't suggest what you've already tried.

Asked by jayess on 2019-05-29 18:54:46 UTC

thanks you for your advices, I have just edited it.

Asked by ballaholic on 2019-05-30 07:21:18 UTC

Answers

This is basically a problem with your CMakeLists.txt.

find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  roscpp
  tf
)

These lines are correct.

catkin_package(
  #INCLUDE_DIRS include
  #LIBRARIES robot_setup_tf
  #CATKIN_DEPENDS geometry_msgs roscpp tf
  #DEPENDS system_lib
)

# include
  ${catkin_INCLUDE_DIRS}
)

These lines are clearly not correct and I don't understand how you could not have gotten complaints from CMake about this. As is, this will not setup the include path correctly, so ros/ros.h is not on the include path, leading to the compiler error you show.

The correct statement would be:

include_directories(
  # include
  ${catkin_INCLUDE_DIRS}
)

Some other observations:

link_directories(${catkin_LIBRARY_DIRS})

This is not needed and should be removed.

${catkin_EXPORTED_TARGETS})

${catkin_EXPORTED_TARGETS})

These statements do nothing and should be removed or fixed.

The tutorial you mention does not instruct you to change the CMakeLists.txt other than adding a few lines to get the binaries to build. Did you edit the CMakeLists.txt yourself?

Finally: if you haven't, I would recommend you follow the TF2 version of this tutorial (ie: this one), instead of using TF. TF has been deprecated for a few years now and TF2 should be used instead.

Asked by gvdhoorn on 2019-05-30 02:05:29 UTC

Comments

Hi, I'm sorry that I have wiped the line "$include_directories( " out when I was editing the question, by mistake. They were actually there in my CMakeLists. Followed what you have suggested me, still not working....I am going to leave tf behind, but using tf2 instead, thanks a lot!

Asked by ballaholic on 2019-05-30 04:59:36 UTC

Followed what you have suggested me, still not working

In that case we're going to need to see your complete CMakeLists.txt.

I am going to leave tf behind, but using tf2 instead, thanks a lot!

The tutorial is almost identical, apart from it using some parts from TF2. If you're currently having issues with this not compiling, I would expect the same issues with the TF2 tutorial.

Asked by gvdhoorn on 2019-05-30 05:24:18 UTC

Sure, I have edited the question, so that you can take a look at my complete CMakeLists file.

Asked by ballaholic on 2019-05-30 07:11:21 UTC

Well I have no idea what is going on with the font above.....the bold characters are the ones that in comment( the lines behind "#" )

Asked by ballaholic on 2019-05-30 07:14:11 UTC