Unsolved Cross-compile MySQL driver for RPi3
-
Hi, I'm developing an application for Raspberrypi 3 that will interact with a mysql server. I'm using Yocto as operative system. I would like to cross-compile the driver for mysql. I'm developing on Ubuntu, I've installed libmysqlclient-dev and libmysqld-dev (via apt-get install). Following the tutorial I've added INCLUDEPATH and LIBS to my .pro file.
QT += core gui sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = MySqlTest TEMPLATE = app target.path = /opt/$${TARGET}/bin INSTALLS += target SOURCES += main.cpp\ widget.cpp INCLUDEPATH += /usr/include/mysql LIBS += -L/usr/lib/x86_64-linux-gnu -lmysqlclient_r HEADERS += widget.h FORMS += widget.ui
When I try to build, deploy, then run it wont work, I get those errors:
cannot find -lmysqlclient_r
/usr/lib/x86_64-linux-gnu/libQt5Widgets.so:-1: error: file not recognized: File format not recognizedWhat I'm doing wrong? Thanks for your help
-
Hi and welcome to devnet,
You are trying to link to your desktop version of the MySQL libraries. You need to use the the ARM version of them.
-
How can I obtain the ARM version of the MySQL libraries in a folder on my local machine?
I've tried downloading libmysqlclient-dev (via apt-get install) on Raspbian, then copied the /usr folder on my local machine. Then I've changed the path in INCLUDEPATH and LIBS as this:QT += core gui sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = MySqlTest TEMPLATE = app target.path = /opt/$${TARGET}/bin INSTALLS += target SOURCES += main.cpp\ widget.cpp INCLUDEPATH += /home/andrea/Scaricati/sysroot/usr/include/mysql LIBS += -L/home/andrea/Scaricati/sysroot/usr/lib/arm-linux-gnueabihf -lmysqlclient_r HEADERS += widget.h FORMS += widget.ui
But it keeps giving me error such:
cannot find libc.so.6
cannot find libc_nonshared.a
cannot find ld-linux-armhf.so.3Can you suggest the correct procedure (where to find the right libraries to download) and how to link them correctly in the .pro file?
Thanks for your support
-
You should use the sysroot of your device when cross-compiling so you ensure you have all the correct libraries available.
-
I've copied the MySQL directory in the include folder of the poky's sysroot, and the shared mysqlclient libraries too in the /usr/lib directory like this:
QT += core gui sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = MySqlTest TEMPLATE = app target.path = /opt/$${TARGET}/bin INSTALLS += target SOURCES += main.cpp\ widget.cpp INCLUDEPATH += /opt/poky/2.3/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi/usr/include/mysql LIBS += -L/opt/poky/2.3/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi/usr/lib -lmysqlclient_r HEADERS += widget.h FORMS += widget.ui
Now it gives me only one error:
/opt/MySqlTest/bin/MySqlTest: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory Application finished with exit code 127.
What could it be?
-
Are you running your application on your device when you get that error ?
-
Yes, I run it from Qt to the remote RPi3. The application runs flawless if I use the Desktop kit. When I use the kit I've made for the Raspberry pi 3 (that has always worked fine) I get that error
-
@endr Does this file exist on your target device: libmysqlclient.so.18 ? If so where?
-
If I copy :
libmysqlclient.a libmysqlclient_r.a libmysqlclient_r.so libmysqlclient_r.so.18 ibmysqlclient_r.so.18.0.0 libmysqlclient.so libmysqlclient.so.18 libmysqlclient.so.18.0.0
to /usr/lib on my target device I get:
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers:
otherwise, without copying the shared libraries on the remote device (trying to crosscompile them from the local machine) I keep getting:
/opt/MySqlTest/bin/MySqlTest: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory Application finished with exit code 127.
What can I do?
-
@endr You can try to start your app like this:
QT_DEBUG_PLUGINS=1 && ./my_app
You will get a lot of output, post it here.
The libraries you're copying: are those for your target (ARM)?
-
@jsulm
I connect in ssh to the RPi3, start the application as you suggested:root@rpi3:/opt/MySqlTest/bin# QT_DEBUG_PLUGINS=1 && ./MySqlTest ./MySqlTest: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
If I copy those shared libraries (from the libmysqlclient-dev package downloaded on a Raspbian OS) to /usr/lib I get this:
root@rpi3:/opt/MySqlTest/bin# QT_DEBUG_PLUGINS=1 && ./MySqlTest Unable to query physical screen size, defaulting to 100 dpi. To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters). QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers:
-
-
There is no sqldrivers directory in qt5/plugins, just those:
root@rpi3:/usr/lib/qt5/plugins# ls -l total 68 drwxr-xr-x 2 root root 4096 Jun 14 10:51 bearer drwxr-xr-x 2 root root 4096 Jun 14 11:44 canbus drwxr-xr-x 2 root root 4096 Jun 14 10:51 egldeviceintegrations drwxr-xr-x 2 root root 4096 Jun 14 10:51 generic drwxr-xr-x 2 root root 4096 Jun 14 12:23 geoservices drwxr-xr-x 2 root root 4096 Jun 14 11:43 iconengines drwxr-xr-x 2 root root 4096 Jun 14 12:33 imageformats drwxr-xr-x 2 root root 4096 Jun 14 12:24 lipi_toolkit drwxr-xr-x 2 root root 4096 Jun 14 12:08 mediaservice
What do I need to download?
-
@endr How did you install Qt on RaspberryPi?
-
I'm using Yocto, Qt5 is installed via the meta-qt5 layer during the bitbaking of the image
-
@endr Well, then I don't know what exactly you need to install. Something with qt and mysql. On Ubuntu it is libqt5sql5-mysql package.