Qmysql 驱动程序未加载但可用 [英] Qmysql driver not loaded but it's available

查看:83
本文介绍了Qmysql 驱动程序未加载但可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的数据库(mysql)与 ubuntu 16.04 上的 Qt 库连接起来.
但我遇到了这个错误:

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

ldd/Qt-PATH/Qt5.7.0/5.7/gcc_64/plugins/sqldrivers/libqsqlmysql.so 的结果是:

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)

为了解决这个问题:libmysqlclient_r.so.16 =>未找到我使用以下命令将其链接到 libmysqlclient.so.20.3.2:
cd/usr/lib/x86_64-linux-gnu/sudo ln -s libmysqlclient.so.20.3.2 libmysqlclient_r.so.16

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

我的 Qt 版本是 5.7 离线模式.

My Qt version is 5.7 offline mode.

我该怎么办?

推荐答案

重复10次:

  1. 我永远不会使用符号链接来解决由于不同的 soname 而导致的库丢失问题
  2. 我永远不会使用符号链接来解决由于不同的 soname 而导致的库丢失问题
  3. 我永远不会使用符号链接来解决由于不同的 soname 而导致的库丢失问题
  4. 我永远不会使用符号链接来解决由于不同的 soname 而导致的库丢失问题
  5. 我永远不会使用符号链接来解决由于不同的 soname 而导致的库丢失问题
  6. 我永远不会使用符号链接来解决由于不同的 soname 而导致的库丢失问题
  7. 我永远不会使用符号链接来解决由于不同的 soname 而导致的库丢失问题
  8. 我永远不会使用符号链接来解决由于不同的 soname 而导致的库丢失问题
  9. 我永远不会使用符号链接来解决由于不同的 soname 而导致的库丢失问题
  10. 我永远不会使用符号链接来解决由于不同的 soname 而导致的库丢失问题

永远永远通过符号链接解决这类问题.如果您的系统没有提供库或可执行文件所需的确切 soname,您将需要重新编译该库或可执行文件.库在其文件名中包含 soname 版本号是有原因的,不匹配的 soname 将导致动态链接器/加载器not found.您只是通过为库插入损坏的 soname 来破坏该过程和您的整个系统.

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.

那么,如何重新编译插件使其在 Ubuntu 上运行?

(或者,实际上,任何地方.甚至 Windows 或 Mac.只需调整说明)

(Or, actually, anywhere. Even Windows or Mac. Just adapt the instructions)

循序渐进:

  1. 安装 mysql 开发包.在 Ubuntu 上,它应该是 libmysqlclient-dev 包,但请仔细检查是否在您的特定 Ubuntu 版本上更改了名称.继续 https://packages.ubuntu.com 并使用基于文件的搜索来查找 mysql.h.
  2. 从安装程序运行维护工具,并要求它也安装 Qt 源组件.您将在 Qt 安装目录中找到该工具.
  3. 转到INSTALL_DIR/Src/5.7/qtbase/src/plugins/sqldrivers/mysql(根据实际情况调整INSTALL_DIR5.7).
  4. 运行右边 qmake.正确的是来自相同 Qt 安装的版本,并且其版本与源代码匹配.在您的情况下,它可能位于 INSTALL_DIR/5.7/gcc_64/bin/qmake 中.
  5. 运行make.如果由于找不到某个库而导致编译失败,请在您的系统上安装所需的软件包.上面链接的 Ubuntu 软件包搜索可能有用.
  6. 一旦make运行成功,它会创建一个全新的libqsqlmysql.so.它应该会自动覆盖 INSTALL_DIR/5.7/gcc_64/plugins/sqldrivers 中的那个.如果出于某种原因它没有被自动覆盖,请手动将其移到那里.
  1. Install the mysql development packages. On Ubuntu it should be the 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.
  2. Run the maintanance tool from the installer, and ask it to also install the Qt source components. You'll find the tool in your Qt installation directory.
  3. Go under INSTALL_DIR/Src/5.7/qtbase/src/plugins/sqldrivers/mysql (adjust INSTALL_DIR and 5.7 to your actual case).
  4. Run the right 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.
  5. Run 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.
  6. Once 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.

完成!享受您的 MySQL 数据库连接.

Done! Enjoy your MySQL database connection.

这篇关于Qmysql 驱动程序未加载但可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆