Qt Mysql build Driver in ubuntu [duplicate] - c++

In Ubuntu 15.04 64 bits I installed Qt5.6 (online installer) and while trying to move my development environment from Windows 7 to Linux I faced the following:
SqlDatabase: QMYSQL driver not loaded
Following this, I managed to find ~/Qt/5.6/gcc_64/plugins/sqldrivers/libqsqlmysql.so and then:
$ ldd libqsqlmysql.so
linux-vdso.so.1 => (0x00007ffffd571000)
libmysqlclient_r.so.16 => not found
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fe94ef24000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007fe94ecec000)
libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fe94ead2000)
libssl.so.10 => not found
libcrypto.so.10 => not found
libQt5Sql.so.5 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libQt5Sql.so.5 (0x00007fe94e88d000)
libQt5Core.so.5 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libQt5Core.so.5 (0x00007fe94e17a000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe94df5c000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe94dc4d000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe94d944000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe94d72e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe94d364000)
libicui18n.so.56 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libicui18n.so.56 (0x00007fe94cec9000)
libicuuc.so.56 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libicuuc.so.56 (0x00007fe94cb11000)
libicudata.so.56 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libicudata.so.56 (0x00007fe94b12e000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe94af29000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fe94ad27000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fe94ab1f000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fe94a80f000)
/lib64/ld-linux-x86-64.so.2 (0x000056024837f000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fe94a5a2000)
Tells libmysqlclient_r.so.16 => not found. In fact, it seems I have a newer version:
find / -name libmysqlclient_r*
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.18
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.18.1.0
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.a
Perhaps that's the problem. Could some one confirm? How should I proceed?

First and foremost, double check that you have the packages containing libssl.so, libcrypto.so and libmysqlclient_r.so installed (looks like you have this last one, it's extremely likely you also have the first two, but just double check).
Then, your problem is that you have those shared objects with a different SONAME, sign that they're binary incompatible with the plugin shipped with Qt, which therefore needs to be recompiled.
Therefore:
install the development versions of the packages found above (libssl-dev, mysql-client-dev or similar).
run the MaintenanceTool from your Qt installation, and be sure to select to install Qt's source code too.
Go in QTDIR/5.6/Src/qtbase/src/plugins/sqldrivers/mysql/.
Run the right qmake, i.e. the one coming from that installation of Qt (not the system wide one or similar). Best way to be sure is providing the full path to it: QTDIR/5.6/gcc_64/bin/qmake.
Run make. Hopefully this will just work™; if it complains about some missing libraries, install them and rerun make.
This should now have produced a new libqsqlmysql.so plugin; overwrite the old one with this new one.

I am using Ubuntu 18.04.4 and compiling my project using system's Qt5. The driver is successfully loaded after I install libqt5sql5-mysql package.
sudo apt-get install libqt5sql5-mysql

There are two fixes for this issue. First try and locate the qtbase folder located within your qt directory and try run ./configure -plugin-sql-mysql which will activate the driver if they're missing.
If this doesn't solve your issue, I suggest that you double check your code and try running one of the Qt examples which makes a connection to the Sql databases. I.e. modify the example code which connects to a local SQLite database changing the parameter to MySQL. If this example doesn't throw 'Driver not loaded error' then follow the step below.
Make sure you're using the static function of the QSqlDatabase i.e. rather than using
QSqlDatabase *db = new QSqlDatabase();
db->addDatabase("QMYSQL");
you should be doing
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");

I also have the same problem with Qt5.11.1 and my OS is Ubuntu16.04 and I have resolve the problem by installing libmysqlclient18 from here
https://launchpad.net/ubuntu/xenial/amd64/libmysqlclient18/5.6.25-0ubuntu1
After download run the command from download directory,
sudo dpkg -i libmysqlclient18_5.6.25-0ubuntu1_amd64.deb

For use MySql with PyQt5 on Raspberry Pi, it's fine to install:
sudo apt-get install libqt5sql5-mysql
and
sudo apt-get install libqt5sql5-mysql

Related

ldd does not find shared object and findes it at the same time

I was trying to deploy project with linuxdeployqt and when I run it with this command
linuxdeployqt ./installer-base-temp/TargetX -bundle-non-qt-libs -qmldir="../source/" -extra-plugins=sqldrivers,iconengines,mediaservice -always-overwrite -unsupported-allow-new-glibc
it shows the following error
ERROR: ldd outputLine: "libsamba-debug-samba4.so => not found"
ERROR: for binary: "/usr/lib64/samba/libsamba-modules-samba4.so"
ERROR: Please ensure that all libraries can be found by ldd. Aborting.
The strange thing is that when I run ldd /usr/lib64/samba/libsamba-modules-samba4.so
this is what I get
linux-vdso.so.1 (0x00007ffc295ea000)
libsamba-util.so.0 => /lib64/libsamba-util.so.0 (0x00007fb854716000)
libsamba-errors.so.1 => /lib64/libsamba-errors.so.1 (0x00007fb8545ca000)
libsamba-debug-samba4.so => not found
libtalloc.so.2 => /lib64/libtalloc.so.2 (0x00007fb8545bd000)
libc.so.6 => /lib64/libc.so.6 (0x00007fb8543bc000)
libgenrand-samba4.so => /usr/lib64/samba/libgenrand-samba4.so (0x00007fb8543b5000)
libsocket-blocking-samba4.so => /usr/lib64/samba/libsocket-blocking-samba4.so (0x00007fb8543b0000)
libsamba-debug-samba4.so => /usr/lib64/samba/libsamba-debug-samba4.so (0x00007fb8543a3000)
libtime-basic-samba4.so => /usr/lib64/samba/libtime-basic-samba4.so (0x00007fb85439e000)
...
So ldd actually finds libsamba-debug-samba4.so to be located at /usr/lib64/samba/libsamba-debug-samba4.so, but at the same time it does not find it.
I have already tired to reinstall the package with sudo dnf reinstall samba-client-libs and after that run ldconfig, moreover I have tried to run it after removing /etc/ld.so.cache. It had no effect.
I am running Fedora 36 Workstation, with kernel version 5.17.13-300.fc36.x86_64.
Can someone explain why this happens and how to fix it.

QSqlDatabase: QMYSQL driver not loaded on Ubuntu 15.04 64bits

In Ubuntu 15.04 64 bits I installed Qt5.6 (online installer) and while trying to move my development environment from Windows 7 to Linux I faced the following:
SqlDatabase: QMYSQL driver not loaded
Following this, I managed to find ~/Qt/5.6/gcc_64/plugins/sqldrivers/libqsqlmysql.so and then:
$ ldd libqsqlmysql.so
linux-vdso.so.1 => (0x00007ffffd571000)
libmysqlclient_r.so.16 => not found
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fe94ef24000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007fe94ecec000)
libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fe94ead2000)
libssl.so.10 => not found
libcrypto.so.10 => not found
libQt5Sql.so.5 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libQt5Sql.so.5 (0x00007fe94e88d000)
libQt5Core.so.5 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libQt5Core.so.5 (0x00007fe94e17a000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe94df5c000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe94dc4d000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe94d944000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe94d72e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe94d364000)
libicui18n.so.56 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libicui18n.so.56 (0x00007fe94cec9000)
libicuuc.so.56 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libicuuc.so.56 (0x00007fe94cb11000)
libicudata.so.56 => /home/user/Qt/5.6/gcc_64/plugins/sqldrivers/../../lib/libicudata.so.56 (0x00007fe94b12e000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe94af29000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fe94ad27000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fe94ab1f000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fe94a80f000)
/lib64/ld-linux-x86-64.so.2 (0x000056024837f000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fe94a5a2000)
Tells libmysqlclient_r.so.16 => not found. In fact, it seems I have a newer version:
find / -name libmysqlclient_r*
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.18
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.18.1.0
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.a
Perhaps that's the problem. Could some one confirm? How should I proceed?
First and foremost, double check that you have the packages containing libssl.so, libcrypto.so and libmysqlclient_r.so installed (looks like you have this last one, it's extremely likely you also have the first two, but just double check).
Then, your problem is that you have those shared objects with a different SONAME, sign that they're binary incompatible with the plugin shipped with Qt, which therefore needs to be recompiled.
Therefore:
install the development versions of the packages found above (libssl-dev, mysql-client-dev or similar).
run the MaintenanceTool from your Qt installation, and be sure to select to install Qt's source code too.
Go in QTDIR/5.6/Src/qtbase/src/plugins/sqldrivers/mysql/.
Run the right qmake, i.e. the one coming from that installation of Qt (not the system wide one or similar). Best way to be sure is providing the full path to it: QTDIR/5.6/gcc_64/bin/qmake.
Run make. Hopefully this will just work™; if it complains about some missing libraries, install them and rerun make.
This should now have produced a new libqsqlmysql.so plugin; overwrite the old one with this new one.
I am using Ubuntu 18.04.4 and compiling my project using system's Qt5. The driver is successfully loaded after I install libqt5sql5-mysql package.
sudo apt-get install libqt5sql5-mysql
There are two fixes for this issue. First try and locate the qtbase folder located within your qt directory and try run ./configure -plugin-sql-mysql which will activate the driver if they're missing.
If this doesn't solve your issue, I suggest that you double check your code and try running one of the Qt examples which makes a connection to the Sql databases. I.e. modify the example code which connects to a local SQLite database changing the parameter to MySQL. If this example doesn't throw 'Driver not loaded error' then follow the step below.
Make sure you're using the static function of the QSqlDatabase i.e. rather than using
QSqlDatabase *db = new QSqlDatabase();
db->addDatabase("QMYSQL");
you should be doing
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
I also have the same problem with Qt5.11.1 and my OS is Ubuntu16.04 and I have resolve the problem by installing libmysqlclient18 from here
https://launchpad.net/ubuntu/xenial/amd64/libmysqlclient18/5.6.25-0ubuntu1
After download run the command from download directory,
sudo dpkg -i libmysqlclient18_5.6.25-0ubuntu1_amd64.deb
For use MySql with PyQt5 on Raspberry Pi, it's fine to install:
sudo apt-get install libqt5sql5-mysql
and
sudo apt-get install libqt5sql5-mysql

mysql driver for qt database fedora

I understand it's the 100s time someone ask this but I'm still unable to have QMYSQL working.
So I installed qt-mysql but I'm still having the
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE
I copied /usr/lib64/qt4/plugins/sqldrivers/libqsqlmysql.so into /usr/lib64/qt5/plugins/sqldrivers/libqsqlmysql.so but no changes ...
I've also added QT += sql into the .pro file.
So what do I have to do ?
P.S. : I'm on Fedora 21 and I'm using QtCreator 3.3.2 based on Qt 5.4.1.
P.P.S : I also checked if the .so had dependencies problem but there's none :
$ ldd libqsqlmysql.so
linux-vdso.so.1 => (0x00007fff665d1000)
libmysqlclient.so.18 => /usr/lib64/mysql/libmysqlclient.so.18 (0x00007fcb07294000)
libQtSql.so.4 => /lib64/libQtSql.so.4 (0x00007fcb07052000)
libQtCore.so.4 => /lib64/libQtCore.so.4 (0x00007fcb06b63000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fcb06947000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fcb06638000)
libm.so.6 => /lib64/libm.so.6 (0x00007fcb0632f000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fcb06118000)
libc.so.6 => /lib64/libc.so.6 (0x00007fcb05d5b000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fcb05b56000)
libz.so.1 => /lib64/libz.so.1 (0x00007fcb05940000)
libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007fcb0573e000)
libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007fcb05404000)
librt.so.1 => /lib64/librt.so.1 (0x00007fcb051fc000)
/lib64/ld-linux-x86-64.so.2 (0x00007fcb07aa6000)
You can't just copy the Qt4 MYSQL driver into Qt5. Install it from the same place you installed the rest of Qt5. (Package qt5-qtbase-mysql perhaps: https://apps.fedoraproject.org/packages/qt5-qtbase-mysql ).
You should build mysql driver manually. The only driver that comes with the default installation of Qt is Sqlite driver.
Follow the instructions in http://doc.qt.io/qt-5.4/sql-driver.html#qmysql
Install mySQL connector.
Follow instructions here
libmysql.dll needs to be located somewhere where it can be found by the application. To make this happen, you can list it in your global PATH in Control Panel/System/Advanced System Settings/Environment variables or put libmysql.dll in the same folder as the Qt dlls in yourQtDirectory/bin.

Strange Python compilation results with "--enable-shared" flag

I am using Debian (which comes with Python-2.7.3), trying to compile Python-2.7.6 from source for use with mod_wsgi alongside Apache.
Apparently you must use --enable-shared when compiling for mod_wsgi usage, according to numerous answers.
Following these steps:
./configure --enable-shared --prefix=/usr/local/bin/python-2.7.6
make
make install
And then checking the interactive shell #
/usr/local/bin/python-2.7.6/bin/python
I am greeted with "Python 2.7.3 (default, Jan 2 2013, 14:09:21)" etc
Why is it resulting in Python 2.7.3?
I tried ldd against the executable and this is the result:
linux-vdso.so.1 => (0x00007fff271ff000)
libpython2.7.so.1.0 => /usr/lib/libpython2.7.so.1.0 (0x00007f1545638000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f154541c000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f1545217000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f1545014000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1544d92000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1544a06000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f15447ef000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f15445d9000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1545b40000)
How do I stop it from using the system library and instead use the locally compiled version?
I know that it is a lot easier for me to just revert to using the system installed Python version, and that the real-world difference is zero. But this behaviour seems strange.
When you do the make of Python, run it as:
LD_RUN_PATH=/usr/local/lib make
Setting the environment variable LD_RUN_PATH forces 'python' executable generated to look in /usr/local/lib before /usr/lib for Python shared library.
This is mentioned in the mod_wsgi documentation.
http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Shared_Library
Before doing this again, make sure you do a 'make distclean' and rerun configure to make sure you haven't got old build products around.

libcudart and local build of gcc link against wrong glibc

I am trying to get CUDA5 to work on a shared cluster.
When I invoke the local gcc to build large applications it works just fine. When I use the CUDA wrapper I get an error saying that it can't find certain parts of glib.
Why is CUDA looking at /lib64/libc.so.6, if I specified the local gcc library directory?
[uid002#n001 cuda5test]$ ldd /home/ex/uid002/cuda/lib64/libcudart.so
/home/ex/uid002/cuda/lib64/libcudart.so: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /home/ex/uid002/cuda/lib64/libcudart.so)
linux-vdso.so.1 => (0x00007fff277ff000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f5328da6000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f5328b89000)
librt.so.1 => /lib64/librt.so.1 (0x00007f5328981000)
libstdc++.so.6 => /home/ex/uid002/gcc/lib64/libstdc++.so.6 (0x00007f532867d000)
libm.so.6 => /lib64/libm.so.6 (0x00007f53283f8000)
libgcc_s.so.1 => /home/ex/uid002/gcc/lib64/libgcc_s.so.1 (0x00007f53281e3000)
libc.so.6 => /lib64/libc.so.6 (0x00007f5327e67000)
/lib64/ld-linux-x86-64.so.2 (0x000000335ae00000)
And
[uid002#n001 cuda5test]$ echo $LD_LIBRARY_PATH
/home/ex/uid002/cuda/lib64:/home/ex/uid002/gmp/lib:/home/ex/uid002/mpfr/lib:/home/ex/uid002/mpc/lib:/home/ex/uid002/gcc/lib64
I have tried to reinstall the CUDA package, and this was no help.
libcudart.so: /lib64/libc.so.6: version `GLIBC_2.14' not found
This error means that the libcudart.so library was linked on a system with glibc-2.14 or later. You can only use that library if your system (both at link time and at runtime) has glibc version >= 2.14. Your system does not satisfy prerequisite for libcudart.so. You'll have to use older version of libcudart.so, or upgrade your system.
(Be careful: upgrading glibc incorrectly is a sure way to render the system un-bootable.)
Why is CUDA looking at /lib64/libc.so.6, if I specified the local gcc library directory?
Glibc is not part of GCC distribution, and is completely independent. "local gcc library directory" is unlikely to have libc.so in it.