Ask Your Question
0

compile error with tf transformation [closed]

asked 2015-07-19 10:11:12 -0500

updated 2015-07-19 10:26:25 -0500

Hi everybody,

I have written some codes as below:

#include <ros/ros.h>
#include <tf/transform_broadcaster.h>
#include <nav_msgs/Odometry.h>
int main(int argc,char ** argv){
    ros::init(argc,argv,"odometry_publisher");
    ros::NodeHandle n;
    ros::Publisher pubOdom= n.advertise<nav_msgs::Odometry>("odom",50);
    tf::TransformBroadcaster odomBroadcaster;
    //some other codes
    ros::Rate r(10);
    while(n.ok()){
        //some other codes
        r.sleep();
    }
    //
    return 0;
}

and put

rosbuild_add_executable(OdomOFPS1_X64 src/OdomOFPS1.cpp)

in the end of the "CMakeLists.txt" file.

There is an error when compile:

OdomOFPS1.cpp.o: In function `main':
src/OdomOFPS1.cpp:22: undefined reference to `tf::TransformBroadcaster::TransformBroadcaster()'
src/OdomOFPS1.cpp:127: undefined reference to `tf::TransformBroadcaster::sendTransform(geometry_msgs::TransformStamped_<std::allocator<void> > const&)'
collect2: error: ld returned 1 exit status

It seems like a link error,the compiler could not find the "tf::TransformBroadcaster" class.Should I put the source code of the tf package in my project and compile them together or solve this problem by some other way?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by redskydeng
close date 2015-07-23 21:05:56.889424

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-07-19 11:34:03 -0500

tfoote gravatar image

You need to link the executable against the tf libraries which are installed on your system. There's documentation of how to do that for rosbuild here

edit flag offensive delete link more

Comments

Thanks,tfoote.

I have solved this problem by adding "target_link_libraries(OdomOFPS1_R32 tf)" in the "CMakeLists.txt" file. It seems like that the compiler linked the libtf.so shared object file in the lib directory.

redskydeng gravatar image redskydeng  ( 2015-07-20 04:55:31 -0500 )edit

Isn't it enough to add dependency to tf package in manifest.xml? As I understand rosbuild_init() in CMakeLists.txt will take care of these dependencies, when rosbuild_add_executable() is used.

Boris gravatar image Boris  ( 2015-07-20 15:27:51 -0500 )edit

Hi,Boris,

Should I add <depend package="tf"/> into the manifest.xml? I will try,thank you very much!

redskydeng gravatar image redskydeng  ( 2015-07-21 08:55:07 -0500 )edit

I made a package from scratch and it did work with just a dependency, so it should be enough. Anyway, I guess you have tried it already :)

Boris gravatar image Boris  ( 2015-07-24 16:15:32 -0500 )edit

Boris, YES,It works.Thanks a lot!:D

redskydeng gravatar image redskydeng  ( 2015-07-25 04:27:16 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-07-19 10:11:12 -0500

Seen: 1,173 times

Last updated: Jul 19 '15