我在Qt写一个程序,我有一点问题。编译很好,但我有这个:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
当我在ldd libqsqlmysql.so
中使用/opt/Qt/5.5/gcc_64/plugins/sqldrivers
时,我明白了:
./libqsqlmysql.so: /usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.16: version `libmysqlclient_16' not found (required by ./libqsqlmysql.so)
linux-vdso.so.1 => (0x00007ffe02bb3000)
libmysqlclient_r.so.16 => /usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.16 (0x00007fa3f8431000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fa3f8217000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007fa3f7fde000)
libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fa3f7dc4000)
libssl.so.10 => not found
libcrypto.so.10 => not found
libQt5Sql.so.5 => /opt/Qt/5.5/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007fa3f7b83000)
libQt5Core.so.5 => /opt/Qt/5.5/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007fa3f743d000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa3f721e000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa3f6e9c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa3f6b94000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa3f697c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa3f65b2000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa3f63ae000)
libicui18n.so.54 => /opt/Qt/5.5/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.54 (0x00007fa3f5f3f000)
libicuuc.so.54 => /opt/Qt/5.5/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.54 (0x00007fa3f5b91000)
libicudata.so.54 => /opt/Qt/5.5/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.54 (0x00007fa3f4166000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fa3f3f64000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa3f3d5c000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fa3f3a4d000)
/lib64/ld-linux-x86-64.so.2 (0x0000558b780a6000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fa3f37df000)
我的代码:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("hostname");
db.setDatabaseName("name");
db.setUserName("username");
db.setPassword("password");
有什么问题?
编辑:我尝试安装openssl,但是当我写sudo apt-get install openssl
时,我得到了这个:
Reading package lists... Done
Building dependency tree
Reading state information... Done
openssl is already the newest version.
openssl set to manually installed.
The following packages were automatically installed and are no longer required:
kde-l10n-engb kde-l10n-pl libdlrestrictions1 libkdecore5
linux-headers-4.2.0-16 linux-headers-4.2.0-16-generic linux-headers-4.2.0-18
linux-headers-4.2.0-18-generic linux-headers-4.2.0-19
linux-headers-4.2.0-19-generic linux-image-4.2.0-16-generic
linux-image-4.2.0-18-generic linux-image-4.2.0-19-generic
linux-image-extra-4.2.0-16-generic linux-image-extra-4.2.0-18-generic
linux-image-extra-4.2.0-19-generic linux-signed-image-4.2.0-16-generic
linux-signed-image-4.2.0-18-generic linux-signed-image-4.2.0-19-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
下一个编辑:好的,我再次使用ldd libqmysql.so,我得到了这个:
./libqsqlmysql.so: /usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.16: version `libmysqlclient_16' not found (required by ./libqsqlmysql.so)
linux-vdso.so.1 => (0x00007ffdb25e9000)
libmysqlclient_r.so.16 => /usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.16 (0x00007f54d5b3f000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f54d5925000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f54d56ec000)
libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007f54d54d2000)
libssl.so.10 => /lib/x86_64-linux-gnu/libssl.so.10 (0x00007f54d5269000)
libcrypto.so.10 => /lib/x86_64-linux-gnu/libcrypto.so.10 (0x00007f54d4e26000)
libQt5Sql.so.5 => /opt/Qt/5.5/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007f54d4be6000)
libQt5Core.so.5 => /opt/Qt/5.5/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007f54d44a0000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f54d4281000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f54d3eff000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f54d3bf7000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f54d39df000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f54d3615000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f54d3411000)
libicui18n.so.54 => /opt/Qt/5.5/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.54 (0x00007f54d2fa2000)
libicuuc.so.54 => /opt/Qt/5.5/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.54 (0x00007f54d2bf4000)
libicudata.so.54 => /opt/Qt/5.5/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.54 (0x00007f54d11c9000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f54d0fc7000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f54d0dbf000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f54d0aaf000)
/lib64/ld-linux-x86-64.so.2 (0x000055d80d1dc000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f54d0842000)
答案 0 :(得分:0)
sudo apt-get install openssl
cd /lib/x86_64-linux-gnu
sudo ln -s libssl.so.1.0.0 libssl.so.10
sudo ln -s libcrypto.so.1.0.0 libcrypto.so.10
并且,还要通知您的Qt经销商更改链接器。
注意强>
问题是Qt与您的libmysqlclient
之间存在不兼容问题。现在,我们只能通过
libmysqlclient18
apt-get install libmysqlclient18
它与Qt安装的兼容性不高,因为它需要版本16.
我建议你升级你的Qt安装
答案 1 :(得分:0)
遇到同样的问题,一些谷歌的研究和直觉终于解决了它。 使用Qt5.9.1和Ubuntu 17.10
首先,检查libmysqlclient.so.18 => not found
的错误是否存在
:~/Qt5.9.1/5.9.1/gcc_64/plugins/sqldrivers$ ldd libqsqlmysql.so
其次,搜索libmysqlclient
的位置 :/$ locate libmysqlclient
第三,转到libmysqlclient所在的文件夹,然后创建链接
:/usr/lib/x86_64-linux-gnu$ sudo ln -s libmysqlclient.so.20 libmysqlclient.so.18
并检查之前的链接
ls -alh | grep libmysql
那一刻,没有一个为我解决,我决定进一步查看突触包,并意识到libqt5sql5-mysql
版本5.9.1没有安装,所以安装它解决了问题,但我仍然有做ldd时的消息
./ libqsqlmysql.so:/usr/lib/x86_64-linux-gnu/libmysqlclient.so.18:找不到版本`libmysqlclient_18'(./libqsqlmysql.so要求)
之后,找到了一些链接,指导我找到真正的解决方案,如果你想知道发生了什么,就是这些链接
我下载了第三个链接中所述的库,并且像魅力一样工作。希望它有所帮助!