Reputation: 93
I want to connect my database(mysql) with Qt library on ubuntu 16.04.
But i faced this error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
Result of ldd /Qt-PATH/Qt5.7.0/5.7/gcc_64/plugins/sqldrivers/libqsqlmysql.so
is:
linux-vdso.so.1 => (0x00007fff9d55a000)
libmysqlclient_r.so.16 => not found
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007efc887eb000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007efc885b3000)
libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007efc8839a000)
libssl.so.10 => not found
libcrypto.so.10 => not found
libQt5Sql.so.5 => /home/hassan-setayesh/ProgramFiles/Qt5.7.0/5.7/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007efc88154000)
libQt5Core.so.5 => /home/hassan-setayesh/ProgramFiles/Qt5.7.0/5.7/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007efc87a38000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007efc8781b000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007efc87499000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007efc8718f000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007efc86f79000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007efc86bb0000)
libicui18n.so.56 => /home/hassan-setayesh/ProgramFiles/Qt5.7.0/5.7/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.56 (0x00007efc86715000)
libicuuc.so.56 => /home/hassan-setayesh/ProgramFiles/Qt5.7.0/5.7/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.56 (0x00007efc8635d000)
libicudata.so.56 => /home/hassan-setayesh/ProgramFiles/Qt5.7.0/5.7/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.56 (0x00007efc8497a000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007efc84775000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007efc84573000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007efc8436b000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007efc84059000)
/lib64/ld-linux-x86-64.so.2 (0x0000564692881000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007efc83de9000)
And for solving this : libmysqlclient_r.so.16 => not found
I link it to libmysqlclient.so.20.3.2
with these command:
cd /usr/lib/x86_64-linux-gnu/
sudo ln -s libmysqlclient.so.20.3.2 libmysqlclient_r.so.16
My Qt version is 5.7 offline mode.
what should i do?
Upvotes: 0
Views: 1538
Reputation: 22734
Never ever solve that kind of problems via symlinking. If your system does not provide the exact soname required by a library or an executable, you'll need to recompile that library or executable. There is a reason why libraries have the soname version number in their file names, and a mismatching soname will result in a not found
for the dynamic linker/loader. You're just breaking that process and your entire system by inserting a broken soname for a library.
/usr/lib/x86_64-linux-gnu/
and remove it. Do it now.Then, how to recompile the plugin so that it works on Ubuntu?
(Or, actually, anywhere. Even Windows or Mac. Just adapt the instructions)
Step by step:
libmysqlclient-dev
package, but double check in case the name changed on your particular Ubuntu edition. Go on https://packages.ubuntu.com and use the file-based search to look for mysql.h
.INSTALL_DIR/Src/5.7/qtbase/src/plugins/sqldrivers/mysql
(adjust INSTALL_DIR
and 5.7
to your actual case).qmake
. The right one is the one coming from the same installation of Qt, and whose version matches the sources. In your case it's likely to be in INSTALL_DIR/5.7/gcc_64/bin/qmake
.make
. If it fails to compile due to some library not found, install the required packages on your system. The Ubuntu package search linked above may be useful.make
runs successfully, it will create a brand new libqsqlmysql.so
. It should automatically overwrite the one in INSTALL_DIR/5.7/gcc_64/plugins/sqldrivers
. If for any reason it's not automatically overwritten, move it manually there.Done! Enjoy your MySQL database connection.
Upvotes: 2