我尝试在Qtcreator中制作一个rosbag阅读器。我创建了一个项目,我只想阅读包内的信息。 这是我的专业档案:
QT += core
QT -= gui
CONFIG += c++11
TARGET = ROSBag_Reader
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
LIBS += -lboost_system
LIBS+= -lpthread
LIBS+= -L/usr/lib/x86_64-linux-gnu
LIBS+= -ltf2_ros
LIBS+= -lrostime
LIBS+= -lrospack
LIBS+= -lroslz4
LIBS+= -lroslib
LIBS+= -lroscpp_serialization
LIBS+= -lroscpp
LIBS+= -lrosconsole_print
LIBS+= -lrosconsole_bridge
LIBS+= -lrosconsole_backend_interface
LIBS+= -lrosconsole
LIBS+= -lrosbag_storage
LIBS+= -lrosbag
SOURCES += main.cpp
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
我的main.cpp:
#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <std_msgs/Int32.h>
#include <std_msgs/String.h>
#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH
int main(int argc, char *argv[])
{
rosbag::Bag bag;
bag.open("/home/xxx/Bureau/Developpement/ROSBag_Reader/data/dataset_table.bag", rosbag::bagmode::Read);
std::vector<std::string> topics;
topics.push_back(std::string("chatter"));
topics.push_back(std::string("numbers"));
rosbag::View view(bag, rosbag::TopicQuery(topics));
foreach(rosbag::MessageInstance const m, view)
{
std_msgs::String::ConstPtr s = m.instantiate<std_msgs::String>();
// if (s != NULL)
// std::cout << s->data << std::endl;
/*
std_msgs::Int32::ConstPtr i = m.instantiate<std_msgs::Int32>();
if (i != NULL)
std::cout << i->data << std::endl;*/
}
bag.close();
}
但是当我尝试运行该项目时,我得到了这个错误:
/home/xxx/Qt/5.7/gcc_64/bin/qmake -spec linux-g++ -o Makefile ../ROSBag_Reader/ROSBag_Reader.pro
g++ -Wl,-O1 -Wl,-rpath,/home/xxx/Qt/5.7/gcc_64/lib -o ROSBag_Reader main.o -lboost_system -L/usr/lib/x86_64-linux-gnu -ltf2_ros -lrostime -lrospack -lroslz4 -lroslib -lroscpp_serialization -lroscpp -lrosconsole_print -lrosconsole_bridge -lrosconsole_backend_interface -lrosconsole -lrosbag_storage -lrosbag -L/home/xxx/Qt/5.7/gcc_64/lib -lQt5Core -lpthread
/usr/bin/ld: main.o: référence au symbole non défini «_ZN3ros6HeaderC1Ev»
//usr/lib/x86_64-linux-gnu/libcpp_common.so.0d: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:214 : la recette pour la cible « ROSBag_Reader » a échouée
我不明白这个错误来自哪里。
答案 0 :(得分:0)
您是否尝试过错误消息建议您做什么?将-lcpp_common添加到LIBS