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

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

asked 2019-05-29 16:01:05 -0500

ballaholic gravatar image

updated 2019-05-30 13:55:37 -0500

jayess gravatar image

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>
edit retag flag offensive close merge delete

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.

jayess gravatar image jayess  ( 2019-05-29 18:54:46 -0500 )edit

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

ballaholic gravatar image ballaholic  ( 2019-05-30 07:21:18 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-05-30 02:05:29 -0500

gvdhoorn gravatar image

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.

edit flag offensive delete link more

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!

ballaholic gravatar image ballaholic  ( 2019-05-30 04:59:36 -0500 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2019-05-30 05:24:18 -0500 )edit

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

ballaholic gravatar image ballaholic  ( 2019-05-30 07:11:21 -0500 )edit

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 "#" )

ballaholic gravatar image ballaholic  ( 2019-05-30 07:14:11 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2019-05-29 16:01:05 -0500

Seen: 1,626 times

Last updated: May 30 '19