gpt4 book ai didi

c++ - 对 image_transport 的 undefined reference

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:11:11 24 4
gpt4 key购买 nike

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

我的主要问题:

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

最佳答案

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

<build_depend>image_transport</build_depend>

<run_depend>image_transport</run_depend>

和您的 CMakeLists.txt:

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

关于c++ - 对 image_transport 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20482782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com