Robotics StackExchange | Archived questions

I encounter some problems when compiling the code providing by ros tutorial saying that it is not included ros.h

Below is the false cause:

/home/ryan/catkin_ws/src/robot_setup_tf/src/tf_broadcaster.cpp:1:10: warning: missing terminating " character
    1 | #include "ros/ros.h
      |          ^
/home/ryan/catkin_ws/src/robot_setup_tf/src/tf_broadcaster.cpp:1:10: error: #include expects "FILENAME" or <FILENAME>
    1 | #include "ros/ros.h
      |          ^~~~~~~~~~
/home/ryan/catkin_ws/src/robot_setup_tf/src/tf_listener.cpp:1:10: fatal error: ros/ros.h: 没有那个文件或目录
    1 | #include "ros/ros.h"
      |          ^~~~~~~~~~~
compilation terminated.
/home/ryan/catkin_ws/src/robot_setup_tf/src/tf_broadcaster.cpp:2:10: fatal error: tf/transform_broadcaster.h: 没有那个文件或目录
    2 | #include <tf/transform_broadcaster.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [robot_setup_tf/CMakeFiles/tf_listener.dir/build.make:63:robot_setup_tf/CMakeFiles/tf_listener.dir/src/tf_listener.cpp.o] 错误 1
make[2]: *** [robot_setup_tf/CMakeFiles/tf_broadcaster.dir/build.make:63:robot_setup_tf/CMakeFiles/tf_broadcaster.dir/src/tf_broadcaster.cpp.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:495:robot_setup_tf/CMakeFiles/tf_listener.dir/all] 错误 2
make[1]: *** 正在等待未完成的任务....
make[1]: *** [CMakeFiles/Makefile2:522:robot_setup_tf/CMakeFiles/tf_broadcaster.dir/all] 错误 2
make: *** [Makefile:141:all] 错误 2
Invoking "make -j16 -l16" failed

And following is my Cmaklist:

cmake_minimum_required(VERSION 3.0.2)
project(robot_setup_tf)


find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  roscpp
  tf
)


catkin_package()
include_directories(${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})

Asked by ryantysre on 2023-07-06 13:13:39 UTC

Comments

In the future, please format code and error messages using the 101010 button. It makes them much more readable. In this question, I did it for you.

Asked by Mike Scheutzow on 2023-07-07 07:50:02 UTC

Thanks for your help.

Asked by ryantysre on 2023-07-09 22:42:06 UTC

Answers

First error:

#include "ros/ros.h

You are missing the second double quote, exactly like the error message tells you.

Second error:

  • Before doing the build, did you source the ros setup.bash file? You need to do this in any terminal window you use for ros.
  • your CMakeLists.txt should specify c++ 11 or higher.
  • your catkin_package() statement is missing the CATKIN_DEPENDS part.

You commented:

include_directories( include ${catkin_INCLUDE_DIRS} ) into new one: include_directories(include ${catkin_INCLUDE_DIRS} /opt/ros/noetic/include )

This should not be necessary and is not a good workaround. It is better to put the proper statements in your CMakeLists.txt file. The are a large number of noetic packages you could look at to see how it should be done.

Asked by Mike Scheutzow on 2023-07-07 08:13:36 UTC

Comments

Thanks for your answer.But unfortunately it did not help me in this circumstance.I source the setup.bash as well as correct the second quote and try to catkin_make this workspace,the same problem occurs again,However when I try to change the original include_dir which is:

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

into new one:

include_directories(include
 ${catkin_INCLUDE_DIRS}
        /opt/ros/noetic/include
)

then the original faults(could not find ros/ros.h) is gone but occuring new problem:

/usr/bin/ld: CMakeFiles/tf_listener.dir/src/tf_listener.cpp.o: in function 'transformPoint(tf::TransformListener const&)':tf_listener.cpp:(.text+0x105): undefined reference to tf::TransformListener::transformPoint(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, geometry_msgs::PointStamped_<std::allocator<void> > const&, geometry_msgs::PointStamped_<std::allocator<void> >&) cons

Asked by ryantysre on 2023-07-09 23:04:58 UTC