对image_transport的未定义引用

时间:2013-12-09 23:09:40

标签: c++ ros

我正在开发一个ROS Qt GUI应用程序,我在ROS Hydro上面临一个问题(我在使用ROS Fuerte时遇到了同样的问题)。我的项目无法像image_transport.h那样识别我的库。我将它添加到qnode.hpp文件的开头,但它没有解决问题。

我的主要问题:

  

/home/attila/catkin_ws/src/arayuz/src/qnode.cpp:-1:错误:未定义引用`image_transport :: ImageTransport :: ImageTransport(ros :: NodeHandle const&)'

这是生成错误的代码:

#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)
}
} 

2 个答案:

答案 0 :(得分:12)

为了链接ROS库,您需要将依赖项添加到package.xml文件中:

<build_depend>image_transport</build_depend>

<run_depend>image_transport</run_depend>

以及CMakeLists.txt

find_package(catkin REQUIRED COMPONENTS
    ...
    image_transport
    ...
)

答案 1 :(得分:0)

仅将标头添加到编译中是不够的:错误消息指出您已成功编译代码但无法链接可执行文件。您还需要找到实现image_transport代码的库并将其链接到您的可执行文件。我不知道ros,但here是一个链接,似乎描述了如何使用这个库构建代码。