2013-12-09 106 views
5

我正在開發一個ROS Qt GUI應用程序,並面臨ROS Hydro的一個問題(我在ROS Fuerte上工作時遇到同樣的問題)。我的項目無法識別我的圖書館,如image_transport.h。我將它添加到qnode.hpp文件的開頭,但它沒有解決問題。對image_transport的未定義引用

我的主要問題:

/home/attila/catkin_ws/src/arayuz/src/qnode.cpp:-1: error: undefined reference to `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) 
} 
} 
+0

請補充說明產生錯誤 – Hilikus

回答

9

爲了庫需要依賴添加到您的package.xml文件對ROS鏈接:

<build_depend>image_transport</build_depend> 

<run_depend>image_transport</run_depend> 

和你CMakeLists.txt

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

我的代碼試圖將該行添加到我的package.xml中,但沒有任何更改:(可以將此問題與automoc相關 –

+1

我最後解決了它..你是對的,我將這些代碼添加到package.xml,並且我還添加了package(。 ... imagetransport ... )我的CMakeList.txt最後的問題解決了...... –

+0

我編輯了CMakeLists.txt丟失的註釋到你的答案。我希望你對此很好。 – luator

0

只需添加標題到編輯是不夠的:該錯誤消息,您成功地規定編譯代碼但未能鏈接可執行文件。您還需要找到執行image_transport代碼的庫並將其鏈接到您的可執行文件。我不知道ROS,但here是一個鏈接,似乎描述如何使用此庫建立代碼。