undefined reference to `tf::TransformBroadcaster::TransformBroadcaster()'
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 catkinpackage.
at package.xml I add `<builddepend>tf and
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;
}
Asked by HiJane on 2018-05-21 08:12:41 UTC
Answers
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.
Asked by PeteBlackerThe3rd on 2018-05-22 04:30:26 UTC
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 )
Asked by HiJane on 2018-05-22 04:46:25 UTC
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} )
Asked by HiJane on 2018-05-22 04:47:20 UTC
But I delete the
Asked by HiJane on 2018-05-22 04:48:34 UTC
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.
Asked by jarvisschultz on 2018-05-22 07:30:42 UTC
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
)
Asked by Victor_Kash on 2021-08-31 06:51:51 UTC
Comments
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)
Asked by jarvisschultz on 2018-05-21 09:33:26 UTC
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?Asked by PeteBlackerThe3rd on 2018-05-21 10:23:02 UTC
Yes I have the #include.this is my source code.JUst like the turtorials of tf
include"ros/ros.h"
include
include
string turtle_name; void poseCallback(const turtlesim::PoseCo{ static tf::TransformBroadcaster br;
Asked by HiJane on 2018-05-21 23:26:23 UTC
@jarvisschultz what's the mean of minus any boilerplate comments? I dont understans, please.
Asked by HiJane on 2018-05-21 23:39:47 UTC
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.Asked by jarvisschultz on 2018-05-22 07:29:34 UTC