Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to image_transport

Tags:

c++

ros

I am developing a ROS Qt GUI application and I face a problem on ROS Hydro (I had the same problem while working on ROS Fuerte). My project does not recognize my library like image_transport.h. I added it to the beginning of the qnode.hpp file but it did not solve the problem.

My major problem:

/home/attila/catkin_ws/src/arayuz/src/qnode.cpp:-1: error: undefined reference to `image_transport::ImageTransport::ImageTransport(ros::NodeHandle const&)'

This is the code that generates the error:

#include "ros/ros.h"
#include "ros/network.h"
#include "string"
#include "std_msgs/String.h"
#include "sstream"
#include "../include/arayuz/qnode.hpp"

namespace enc=sensor_msgs::image_encodings;

static const char WINDOW[ ]="Kinect";

namespace arayuz {

QNode::QNode(int argc, char** argv ) :
    init_argc(argc),
    init_argv(argv)
    {}

QNode::~QNode() {
    if(ros::isStarted()) {
      ros::shutdown(); // explicitly needed since we use ros::start();
      ros::waitForShutdown();
    }
    cv::destroyWindow(WINDOW);
    wait();
}

bool QNode::init() {
    ros::init(init_argc,init_argv,"arayuz");

    if ( ! ros::master::check() ) {
        return false;
    }

    ros::start(); // explicitly needed since our nodehandle is going out of scope.

    ros::NodeHandle n;
    // Add your ros communications here.

    image_transport::ImageTransport it(n);
    imagesub = it.subscribe("/kinectCamera", 1,&QNode::chatterimage,this);

    start();

    return true;
}


bool QNode::init(const std::string &master_url, const std::string &host_url) {
    std::map<std::string,std::string> remappings;

    remappings["__master"] = master_url;
    remappings["__hostname"] = host_url;

    ros::init(remappings,"arayuz");

    if ( ! ros::master::check() ) {
        return false;
    }

    ros::start(); // explicitly needed since our nodehandle is going out of scope.

    ros::NodeHandle n;
    // Add your ros communications here.

    image_transport::ImageTransport it(n);

    imagesub = it.subscribe("/kinectCamera",1,&QNode::chatterimage,this);

    start();

    return true;
}

void QNode::chatterimage(const sensor_msgs::ImageConstPtr& msg)
{
    rgbimage=cv_bridge::toCvCopy(msg,enc::BGR8);

    Q_EMIT chatterimageupdate();
}

void QNode::run() {
    while ( ros::ok() ) {
        ros::spin();
    }

    std::cout << "Ros shutdown, proceeding to close the gui." << std::endl;
    Q_EMIT rosShutdown(); // used to signal the gui for a shutdown (useful to roslaunch)
}
} 
like image 227
Attila AKINCI Avatar asked Dec 09 '13 23:12

Attila AKINCI


2 Answers

In order to link against ROS libraries you need to add the dependency to your package.xml file:

<build_depend>image_transport</build_depend>

<run_depend>image_transport</run_depend>

and to your CMakeLists.txt:

find_package(catkin REQUIRED COMPONENTS
    ...
    image_transport
    ...
)
like image 80
rossburgo Avatar answered Nov 11 '22 03:11

rossburgo


Just adding the header to your compilation isn't sufficient: the error message states that you successfully compiled the code but it failed to link the executable. You will also need to find the library implementing the image_transport code and link it to your executable. I have no idea of ros but here is a link which seems to describe how to build code using this library.

like image 45
Dietmar Kühl Avatar answered Nov 11 '22 03:11

Dietmar Kühl