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

Writing a tf broadcaster (C++) errors

asked 2019-05-16 02:29:15 -0600

Kora11101 gravatar image

updated 2019-05-16 08:11:56 -0600

gvdhoorn gravatar image

Hello,

after adding those lines to CMakeLists.txt:

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

Errors like this appeared:

 CMakeFiles/turtle_tf_broadcaster.dir/src/turtle_tf_broadcaster.cpp.o: In function `poseCallback(boost::shared_ptr<turtlesim::Pose_<std::allocator<void> > const> const&)':
turtle_tf_broadcaster.cpp:(.text+0x4f): undefined reference to `tf::TransformBroadcaster::TransformBroadcaster()'
turtle_tf_broadcaster.cpp:(.text+0x1b7): undefined reference to `ros::Time::now()'
turtle_tf_broadcaster.cpp:(.text+0x1fc): undefined reference to `tf::TransformBroadcaster::sendTransform(tf::StampedTransform const&)'
CMakeFiles/turtle_tf_broadcaster.dir/src/turtle_tf_broadcaster.cpp.o: In function `main':
turtle_tf_broadcaster.cpp:(.text+0x322): undefined reference to `ros::init(int&, char**, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'
turtle_tf_broadcaster.cpp:(.text+0x356): undefined reference to `ros::console::g_initialized'
turtle_tf_broadcaster.cpp:(.text+0x366): undefined reference to `ros::console::initialize()'
turtle_tf_broadcaster.cpp:(.text+0x3bb): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ros::console::levels::Level)'
turtle_tf_broadcaster.cpp:(.text+0x3fc): undefined reference to `ros::console::setLogLocationLevel(ros::console::LogLocation*, ros::console::levels::Level)'
turtle_tf_broadcaster.cpp:(.text+0x406): undefined reference to `ros::console::checkLogLocationEnabled(ros::console::LogLocation*)'
turtle_tf_broadcaster.cpp:(.text+0x458): undefined reference to `ros::console::print(ros::console::FilterBase*, void*, ros::console::levels::Level, char const*, int, char const*, char const*, ...)'
turtle_tf_broadcaster.cpp:(.text+0x4bf): undefined reference to `ros::NodeHandle::NodeHandle(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&)'
turtle_tf_broadcaster.cpp:(.text+0x571): undefined reference to `ros::spin()'
turtle_tf_broadcaster.cpp:(.text+0x585): undefined reference to `ros::Subscriber::~Subscriber()'
turtle_tf_broadcaster.cpp:(.text+0x594): undefined reference to `ros::NodeHandle::~NodeHandle()'
turtle_tf_broadcaster.cpp:(.text+0x636): undefined reference to `ros::NodeHandle::~NodeHandle()'
turtle_tf_broadcaster.cpp:(.text+0x667): undefined reference to `ros::NodeHandle::~NodeHandle()'
turtle_tf_broadcaster.cpp:(.text+0x698): undefined reference to `ros::Subscriber::~Subscriber()'
turtle_tf_broadcaster.cpp:(.text+0x6c0): undefined reference to `ros::Subscriber::~Subscriber()'
turtle_tf_broadcaster.cpp:(.text+0x6d4): undefined reference to `ros::Subscriber::~Subscriber()'
turtle_tf_broadcaster.cpp:(.text+0x6e8): undefined reference to `ros::NodeHandle::~NodeHandle()'
CMakeFiles/turtle_tf_broadcaster.dir/src/turtle_tf_broadcaster.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
turtle_tf_broadcaster.cpp:(.text+0x7b0): undefined reference to `boost::system::generic_category()'
turtle_tf_broadcaster.cpp:(.text+0x7bc): undefined reference to `boost::system::generic_category()'
turtle_tf_broadcaster.cpp:(.text+0x7c8): undefined reference to `boost::system::system_category()'
CMakeFiles/turtle_tf_broadcaster.dir/src/turtle_tf_broadcaster.cpp.o: In function `tf2_ros::TransformBroadcaster::~TransformBroadcaster()':
turtle_tf_broadcaster.cpp:(.text._ZN7tf2_ros20TransformBroadcasterD2Ev[_ZN7tf2_ros20TransformBroadcasterD5Ev]+0x1b): undefined reference to `ros::Publisher::~Publisher()'
turtle_tf_broadcaster.cpp:(.text._ZN7tf2_ros20TransformBroadcasterD2Ev[_ZN7tf2_ros20TransformBroadcasterD5Ev]+0x27): undefined reference to `ros::NodeHandle::~NodeHandle()'
turtle_tf_broadcaster.cpp:(.text._ZN7tf2_ros20TransformBroadcasterD2Ev[_ZN7tf2_ros20TransformBroadcasterD5Ev]+0x38): undefined reference to `ros::NodeHandle::~NodeHandle()'
CMakeFiles/turtle_tf_broadcaster.dir/src/turtle_tf_broadcaster.cpp.o: In function `ros::Subscriber ros::NodeHandle::subscribe<turtlesim::Pose_<std::allocator<void> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-05-16 02:44:23 -0600

gvdhoorn gravatar image

updated 2019-05-16 08:14:03 -0600

These are linker errors, indicating that you don't link against (at least) the tf library.

Did you create the package using the command shown in the tutorial? Specifically, this:

catkin_create_pkg learning_tf tf roscpp rospy turtlesim

If you can show the find_package(catkin REQUIRED COMPONENTS ..) part of your CMakeLists.txt, we may be able to spot what is wrong or missing.


Edit:

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

cmake_minimum_required(VERSION 2.8.3)
project(learning_tf)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  tf
  turtlesim
)

This would appear to be a problem of statement order.

It's best not to have the add_executable(..) and target_link_libraries(..) lines at the top of your file.

Move those two lines below the find_package(catkin ..) line.

I expect things to start working then.

Finally, if you haven't yet, you may want to lookup a tutorial or two about CMake. That will make a lot of things related to build scripts and the kinds of errors you posted this question about much clearer.

edit flag offensive delete link more

Comments

Where should tf library be located?

Kora11101 gravatar image Kora11101  ( 2019-05-16 07:40:58 -0600 )edit

On page it is said that: "If everything went well, you should have a binary file called turtle_tf_broadcaster in your devel/lib/learning_tf folder."

I don't have learning_tf folder in devel/lib.

I have pkgconfig and there I have learning_tf.pc.

Is that enough?

Kora11101 gravatar image Kora11101  ( 2019-05-16 12:02:13 -0600 )edit

Could you now compile the package successfully?

gvdhoorn gravatar image gvdhoorn  ( 2019-05-16 12:07:14 -0600 )edit

[ 50%] Linking CXX executable turtle_tf_broadcaster [100%] Built target turtle_tf_broadcaster I guess so :)

Kora11101 gravatar image Kora11101  ( 2019-05-16 12:33:01 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-05-16 02:29:15 -0600

Seen: 677 times

Last updated: May 16 '19