Rosbag reader in qtcreator - c++

I try to make a rosbag reader in Qtcreator. I create a project and I just want to read informations inside the bag.
Here is my pro file:
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
And my 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();
}
But when I try to run the project I get that error:
/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
I don't understand where this error comes.

Did you try what the error messages suggests you to do? add -lcpp_common to your LIBS

Related

Adding ObjectBox to Qt application

I have just tried to add ObjectBox to an empty qt application, but somehow I do not get any further.
I tried to follow the instructions: https://cpp.objectbox.io/installation
I took the win x64 lib from here: https://github.com/objectbox/objectbox-c/releases/tag/v0.17.0
I am always getting undefined reference errors and I do not know why. I guess there must be something wrong with linking in der .pro file?
Thats my .pro file (just edited the last 4 lines):
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/objectbox/lib/ -lobjectbox
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/objectbox/lib/ -lobjectbox
INCLUDEPATH += $$PWD/objectbox/include
DEPENDPATH += $$PWD/objectbox/include
And here ist my main.cpp:
#include <QCoreApplication>
#include "objectbox.hpp"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
printf("Using ObjectBox version %s\n", obx_version_string());
return a.exec();
}
Compiler says the following:
C:/Qt/Tools/mingw730_64/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/temp/obxTut/ObjectBoxTutorial'
g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -W -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_QML_DEBUG -DQT_CORE_LIB -I. -Iobjectbox\include -I..\..\..\Qt\5.12.11\mingw73_64\include -I..\..\..\Qt\5.12.11\mingw73_64\include\QtCore -Idebug -I..\..\..\Qt\5.12.11\mingw73_64\mkspecs\win32-g++ -o debug\main.o main.cpp
In file included from main.cpp:2:0:
objectbox\include/objectbox.hpp:711:21: warning: 'std::vector<long long unsigned int> obx::{anonymous}::idVectorOrThrow(OBX_id_array*)' defined but not used [-Wunused-function]
std::vector<obx_id> idVectorOrThrow(OBX_id_array* cIds) {
^~~~~~~~~~~~~~~
objectbox\include/objectbox.hpp:703:14: warning: 'OBX_id_array obx::{anonymous}::cIdArrayRef(const std::vector<long long unsigned int>&)' defined but not used [-Wunused-function]
OBX_id_array cIdArrayRef(const std::vector<obx_id>& ids) {
^~~~~~~~~~~
g++ -Wl,-subsystem,console -mthreads -o debug\ObjectBoxTutorial.exe debug/main.o -LC:\temp\obxTut\ObjectBoxTutorial\objectbox\lib -lobjectbox C:\Qt\5.12.11\mingw73_64\lib\libQt5Cored.a
debug/main.o: In function `idVectorOrThrow':
C:\temp\obxTut\ObjectBoxTutorial/objectbox/include/objectbox.hpp:712: undefined reference to `obx::internal::throwLastError(int, char const*)'
C:\temp\obxTut\ObjectBoxTutorial/objectbox/include/objectbox.hpp:718: undefined reference to `obx::internal::throwIllegalStateException(char const*, char const*)'
debug/main.o: In function `applyTo':
C:\temp\obxTut\ObjectBoxTutorial/objectbox/include/objectbox.hpp:828: undefined reference to `obx::internal::throwIllegalStateException(char const*, char const*)'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Makefile.Debug:65: debug/ObjectBoxTutorial.exe] Error 1
mingw32-make: *** [Makefile:38: debug] Error 2
mingw32-make[1]: Leaving directory 'C:/temp/obxTut/ObjectBoxTutorial'
23:05:08: The process "C:\Qt\Tools\mingw730_64\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project ObjectBoxTutorial (kit: Desktop Qt 5.12.11 MinGW 64-bit)
When executing step "Make"
Qt 5.12 with MinGW 7.3
The problem is the compiler that you are using, because the library is probably compiled with MSVC and you are trying to build your application with MinGW and use the C++ interface of the library.
this won't work because of name mangling and etc. see How to use libraries compiled with MingW in MSVC?
Thankfully this library also provides a pure C interface "objectbox.h", so including this header instead of the one with "hpp" would also fix your issue.
I was able to build and link a test app by using MSVC 2015 64 Bit.

compilation error of OpenCV cpp code using Qt

I am using a very basic OpenCV code to compile using Qt but every time the following errors are coming.
OpenCV version
OpenCV version : 3.4.3
Major version : 3
Minor version : 4
Subminor version : 3
My code
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat I = imread("path/filename.ppm", 1);
imshow("conv_image",I);
waitKey();
return 0;
}
.pro file
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# 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
SOURCES += main.cpp
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -
lopencv_highgui
Given Error
:-1: warning: libopencv_core.so.3.4, needed by /usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_core.so.2.4
:-1: error: main.o: undefined reference to symbol '_ZN2cv6String10deallocateEv'
/usr/local/lib/libopencv_core.so.3.4:-1: error: error adding symbols: DSO missing from command line
:-1: error: collect2: error: ld returned 1 exit status
In my .pro file, I have used the following line(from the different link I have found 3 ways, I have tried all but failed)
First
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -
lopencv_highgui
Second
INCLUDEPATH +=/usr/local/include/opencv
LIBS +=`pkg-config --libs opencv`
Third
I have used information from here
Please give me suggestion to solve the issue.

SQLiteCpp cross compile error: cannot find a given function in sqlite3.c

I came across a compile error that cannot find the function defined in a given file when I try to add SQLiteCpp source to my qt application. It cost me a half day and I hope some one can kindly help me. Thanks a lot!
build libSQLiteCpp.a and libsqlite3.a
{
get src:
git clone https://github.com/SRombauts/SQLiteCpp.git
cd SQLiteCpp
git submodule init
git submodule update
build libs:
cd /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/ \
&& . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa9hf-neon-poky-linux-gnueabi \
&& ./build.sh
}
edit qt app and its project file
{
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = sqltest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
INCLUDEPATH += /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/include/
INCLUDEPATH += /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/include/SQLiteCpp/
INCLUDEPATH += /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/sqlite3/
LIBS += /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/sqlite3/libsqlite3.a
LIBS += /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/libSQLiteCpp.a
FORMS += mainwindow.ui
}
qt app cross compile error: can not find the function defined in sqlite3.c
{
arm-poky-linux-gnueabi-g++ -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.0/sysro
ots/cortexa9hf-neon-poky-linux-gnueabi -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-O1 -o sqltest main.o mainwindow.o moc_mainwi
ndow.o /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/sqlite3/libsqlite3.a /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp
/build/libSQLiteCpp.a -lQt5Widgets -lQt5Gui -lQt5Core -lGLESv2 -lEGL -lpthread
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/libSQLiteCpp.a(Column.cpp.o): In function `SQLite::Column::getName() const':
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/src/Column.cpp:44: undefined reference to `sqlite3_column_name'
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/libSQLiteCpp.a(Column.cpp.o): In function `SQLite::Column::getOriginName() con
st':
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/src/Column.cpp:51: undefined reference to `sqlite3_column_origin_name'
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/libSQLiteCpp.a(Column.cpp.o): In function `SQLite::Column::getInt() const':
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/src/Column.cpp:58: undefined reference to `sqlite3_column_int'
}
more info
{
ocean#mhc:~/test/qt5_all/sqltest/sqltest$ grep -rns "sqlite3_libversion" /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/SQLiteCpp_example1
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/SQLiteCpp_tests
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/sqlite3/libsqlite3.a
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/sqlite3/CMakeFiles/sqlite3.dir/sqlite3.c.o
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/libSQLiteCpp.a
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/CMakeFiles/SQLiteCpp.dir/src/Database.cpp.o
}
Can somebody tell me why why XLIBS/SQLiteCpp/src/Column.cpp cannot read sqlite3_column_origin_name() from libsqlite3.a (sqlite3.c)? I have built XLIBS/SQLiteCpp/build/sqlite3/libsqlite3.a and then the XLIBS/SQLiteCpp/build/libSQLiteCpp.a !!

SDL2 undefined reference sdl_Main in QtCreator

Im trying to use QtCreator to create a project including SDL2. But SDL is failing to compile correctly and I can't see the error.
My QtCreator .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Psiora
TEMPLATE = app
SOURCES += main.cpp\
ui_mainwindow.cpp
HEADERS += ui_mainwindow.h
FORMS += ui_mainwindow.ui
INCLUDEPATH += "D:\devel\SDL2-2.0.3\i686-w64-mingw32\include\SDL2"
LIBS += -L"D:\devel\SDL2-2.0.3\i686-w64-mingw32\lib" \
-lmingw32 \
-mwindows \
-lSDL2main \
-lSDL2
Main.cpp
#include "ui_mainwindow.h"
#include <QApplication>
#define SDL_MAIN_HANDLED //Let QT Supply WinMain
#include "SDL.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
UI_mainWindow win;
win.show();
return app.exec();
}
Compiler errors
g++ -Wl,-subsystem,windows -mthreads -o debug\Psiora.exe debug/main.o debug/ui_mainwindow.o debug/moc_ui_mainwindow.o -lglu32 -lopengl32 -lgdi32 -luser32 -lqtmaind -LD:\devel\SDL2-2.0.3\i686-w64-mingw32\lib -lmingw32 -mwindows -lSDL2main -lSDL2 -LD:\devel\Qt\5.2.1\mingw48_32\lib -lQt5Widgetsd -lQt5Guid -lQt5Cored
D:\devel\SDL2-2.0.3\i686-w64-mingw32\lib/libSDL2main.a(SDL_windows_main.o): In function `console_main':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/main/windows/SDL_windows_main.c:140: undefined reference to `SDL_main'
collect2.exe: error: ld returned 1 exit status
I don't understand why SDL is giving an undefined reference to sdl_Main, when it has been linked in the correct order. I also don't get where this "/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/main/windows/" has come from when there is no such path on my computer, nor have I added the path myself.
My understanding is the SDL_Main provides WinMain however I wish to use the WinMain provided by Qt instead so I have defined the SDL_MAIN_HANDLED define to stop SDL using SDL_Main.
Addition Information:
OS: Windows 8.1 Pro 32bit
Compiler: MinGW 4.8 - The default one provided with the Qt Installer
Qt: 5.2.1
SDL 2.0.3 - Downloaded directly from libsdl.org, unmodified with no patches.
Add this to your project file to solve this:
win32:QMAKE_LIBS_QT_ENGTRY -= -lqtmain
win32-g++:DEFINES -= QT_NEEDS_QMAIN
or
CONFIG-= windows
QMAKE_LFLAGS += $$QMAKE_LFLAGS_WINDOWS

Inclusion of header files from include/Qt is deprecated

I've recently began working through a C++ Gui Programming with Qt 4 book.
However, I can't get past the first tutorials.
#include <QApplication>
#include <QTextEdit>
int main(int argv, char **args)
{
QApplication app(argv, args);
QTextEdit textEdit;
textEdit.show();
return app.exec();
}
Each time I try to compile this, I get this:
C:\Qt\4.8.0\andrew>qmake -project
C:\Qt\4.8.0\andrew>qmake
C:\Qt\4.8.0\andrew>make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Qt/4.8.0/andrew'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -
DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -
DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\includ
e\QtCore" -I"..\include\QtGui" -I"..\include" -I"." -I"..\include\ActiveQt" -I"d
ebug" -I"..\mkspecs\win32-g++" -o debug\tutone.o tutone.cpp
In file included from tutone.cpp:1:0:
C:\Qt\4.8.0\include\Qt\Qapplication.h:3:10: warning: #warning "Inclusion of head
er files from include/Qt is deprecated." [-Wcpp]
In file included from tutone.cpp:2:0:
C:\Qt\4.8.0\include\Qt\Qpushbutton.h:3:10: warning: #warning "Inclusion of heade
r files from include/Qt is deprecated." [-Wcpp]
tutone.cpp: In function 'int qMain(int, char**)':
tutone.cpp:11:7: error: 'class QApplication' has no member named 'setMainWidget'
mingw32-make[1]: *** [debug/tutone.o] Error 1
mingw32-make[1]: Leaving directory `C:/Qt/4.8.0/andrew'
mingw32-make: *** [debug] Error 2
As I'm new to Qt and fairly new to compiling, I assume the error is on my end. Am I declaring the headers wrong or something?
My .pro file looks like this:
######################################################################
# Automatically generated by qmake (2.01a) Thu Jan 19 12:41:21 2012
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += tutone.h \
C:/Qt/4.8.0/include/Qt/Qapplication.h \
../include/QtGui/qapplication.h \
../src/gui/kernel/qapplication.h \
C:/Qt/4.8.0/include/Qt/Qpushbutton.h \
../include/QtGui/qpushbutton.h \
../src/gui/widgets/qpushbutton.h
SOURCES += tutone.cpp \
tutthree.cpp \
../src/gui/kernel/qapplication.cpp \
../src/gui/widgets/qpushbutton.cpp
Thanks
It's a false error due to a bug in the Qt build setup.
It's not a problem and has been logged on the Qt bug tracker
After running qmake -project you should add QT variable in the .pro file. Then you can remove these odd HEADERS and SOURCES (and link dynamically Qt libraries to your program):
QT += core gui # <-- this line
TEMPLATE = app
TARGET = ProjectNameHere
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += tutone.h
SOURCES += tutone.cpp \
tutthree.cpp \