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

undefined reference to `tf::TransformBroadcaster::TransformBroadcaster()'

asked 2018-05-21 08:12:41 -0500

HiJane gravatar image

updated 2018-05-22 04:24:52 -0500

Hi all when I learn the tf with ros wiki, some questions happened. it said:undefined reference to tf::TransformBroadcaster::TransformBroadcaster() But at the CMakeLists.txt I add tf in the find package and the catkin_package. at package.xml I add <build_depend>tf</build_depend> <build_export_depend>tf</build_export_depend> and <exec_depend>tf</exec_depend>

I dont kown why undefined

Thanks all

this is my code.

#include<iostream>
#include<string>
#include<cstring>
#include"ros/ros.h"
#include <tf/transform_broadcaster.h>
#include <turtlesim/Pose.h>
using namespace std;

string turtle_name;

void poseCallback(const turtlesim::PoseConstPtr &msg)
{
    static tf::TransformBroadcaster br; 

    tf::Transform transform;

    transform.setOrigin(tf::Vector3(msg->x, msg->y, 0.0));

    tf::Quaternion q;
    q.setRPY(0, 0, msg->theta);

    transform.setRotation(q);

    br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "world", turtle_name));
}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "my_tf_broadcaster");

    if(argc != 2)
    {
    ROS_ERROR("need turtle name as argument");
        return -1;
    }

    turtle_name = argv[1];

    ros::NodeHandle node;
    ros::Subscriber sub = node.subscribe(turtle_name + "/pose", 10, &poseCallback);

    ros::spin();

    return 0;
}
edit retag flag offensive close merge delete

Comments

2

This is almost certainly an issue with your CMakeLists.txt file. Would be helpful to include your CMakeLists.txt and package.xml (minus any boilerplate comments)

jarvisschultz gravatar image jarvisschultz  ( 2018-05-21 09:33:26 -0500 )edit

Can you show us your source code too. Do you have the #include <tf/transform_broadcaster.h> statement at the top of your source code?

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-05-21 10:23:02 -0500 )edit

Yes I have the #include <tf transform_broadcaster.h="">.this is my source code.JUst like the turtorials of tf #include"ros/ros.h" #include <tf transform_broadcaster.h=""> #include <turtlesim pose.h=""> string turtle_name; void poseCallback(const turtlesim::PoseCo{ static tf::TransformBroadcaster br;

HiJane gravatar image HiJane  ( 2018-05-21 23:26:23 -0500 )edit

@jarvisschultz what's the mean of minus any boilerplate comments? I dont understans, please.

HiJane gravatar image HiJane  ( 2018-05-21 23:39:47 -0500 )edit
1

When you create a CMakeLists.txt and package.xml using catkin_create_pkg there are a bunch of comments in both files that we don't need to see. These are often referred to as "boilerplate". Getting rid of these is good practice to try and keep questions as short as possible.

jarvisschultz gravatar image jarvisschultz  ( 2018-05-22 07:29:34 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2018-05-22 04:30:26 -0500

I'm not sure if this is the cause of your problem, but you don't need the <build_export_depend> tag in your package.xml file. Just the build and execute tags are needed. Also could you post your CMakeLists.txt too so we can check everything is okay there.

edit flag offensive delete link more

Comments

thanks.here is my CMakeLists.some code find_package(catkin REQUIRED COMPONENTS roscpp rospy tf turtlesim ) catkin_package( INCLUDE_DIRS include LIBRARIES learning_tf CATKIN_DEPENDS roscpp rospy tf turtlesim DEPENDS system_lib )

HiJane gravatar image HiJane  ( 2018-05-22 04:46:25 -0500 )edit

include_directories(

include

${catkin_INCLUDE_DIRS} ) add_executable(turtle_tf_broadcaster src/turtle_tf_broadcaster.cpp) target_link_libraries(turtle_tf_broadcaster ${catkin_LIBRARIES}) install(TARGETS turtle_tf_broadcaster DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} )

HiJane gravatar image HiJane  ( 2018-05-22 04:47:20 -0500 )edit

But I delete the <build_export_depend> there still problem.

HiJane gravatar image HiJane  ( 2018-05-22 04:48:34 -0500 )edit

This is not how to post your CMakeLists.txt. You should really edit your original question and include the file in a code block just like you did with your source code.

jarvisschultz gravatar image jarvisschultz  ( 2018-05-22 07:30:42 -0500 )edit
0

answered 2021-08-07 22:10:13 -0500

Yu. gravatar image

Replacing tf to tf2 will be OK

edit flag offensive delete link more
1

answered 2021-08-31 06:51:51 -0500

Victor_Kash gravatar image

You need to include tf in the find_package part in the CMakeLists.txt

something like this

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  tf
)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-05-21 08:12:41 -0500

Seen: 5,824 times

Last updated: Aug 31 '21