CentOS7 (64位) 下QT5.5 串連MySQL資料庫(driver not loaded)

來源:互聯網
上載者:User

CentOS7 (64位) 下QT5.5 串連MySQL資料庫(driver not loaded)

用qt串連MySQL需要共用庫 libqsqlmysql.so的驅動,路徑在plugin/sqldrivers目錄下,乍看已經可用了,其實不然。

用ldd命令分析一下,libmysqlclient_r.so.16 => not found ,後明顯libmysqlclient_r.so.16 缺少另一個共用庫,他們是依賴關係,解決了這個問題qt才能真的串連到mysql資料庫。而我的/usr/lib64/下的共用庫版本比較高是libmysqlclient.so.18,想到了一個比較投機的想法ln建立符號連結,然而這並沒有什麼卵用。

讓我哭笑不得是QT5.5是我從官網下載的,居然依賴的是低版本,你們編譯的時候能不能不偷懶啊,估計他們直接從低版本拷貝的libqsqlmysql.so,沒辦法了嗎?顯然不是,開啟qt官網下載源碼,自己編譯。下載過程略過,非常好找 http://download.qt.io/official_releases/qt/5.4/5.4.2/submodules/ (暫時沒有qt5.5的源碼),找到qtbase那個大概60M。MySql驅動的路徑為qtbase/src/plugins/sqldrivers/mysql/。
•qmake
•make

然而這還沒有完,make的過程中又找不到動態庫了:

/usr/bin/ld: cannot find -lz
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto

第一個是沒有安裝zlib-devel,直接yum install zlib-devel搞定。

第二第三項找不到是沒有道理的,解決的方法:/usr/lib64/中建立符號連結

ln -s libssl.so.1.0.1e libssl.so

ln -s libcrypto.so.1.0.1e libcrypto.so

再次make,成功。當然這還沒有完,用新的libqsqlmysql.so去替換舊的,這就全部完成了。

再次查看: 

[sqldrivers]ldd libqsqlmysql.so
    linux-vdso.so.1 =>  (0x00007fff2d5fe000)
    libmysqlclient.so.18 => /usr/lib64/mysql/libmysqlclient.so.18 (0x00007feb4ea24000)
    libz.so.1 => /lib64/libz.so.1 (0x00007feb4e80d000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007feb4e5d6000)
    libnsl.so.1 => /lib64/libnsl.so.1 (0x00007feb4e3bd000)
    libssl.so.10 => /lib64/libssl.so.10 (0x00007feb4e150000)
    libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007feb4dd6b000)
    libQt5Sql.so.5 => /home/eric/Qt5.5.0/5.5/gcc_64/lib/libQt5Sql.so.5 (0x00007feb4db2b000)
    libQt5Core.so.5 => /home/eric/Qt5.5.0/5.5/gcc_64/lib/libQt5Core.so.5 (0x00007feb4d3e3000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007feb4d1c7000)
    libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007feb4cec0000)
    libm.so.6 => /lib64/libm.so.6 (0x00007feb4cbbd000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007feb4c9a7000)
    libc.so.6 => /lib64/libc.so.6 (0x00007feb4c5e6000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007feb4c3e1000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007feb4c164000)
    libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007feb4bf1a000)
    libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007feb4bc39000)
    libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007feb4ba35000)
    libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007feb4b800000)
    libicui18n.so.54 => /home/eric/Qt5.5.0/5.5/gcc_64/lib/libicui18n.so.54 (0x00007feb4b391000)
    libicuuc.so.54 => /home/eric/Qt5.5.0/5.5/gcc_64/lib/libicuuc.so.54 (0x00007feb4afe3000)
    libicudata.so.54 => /home/eric/Qt5.5.0/5.5/gcc_64/lib/libicudata.so.54 (0x00007feb495b9000)
    libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007feb493b6000)
    librt.so.1 => /lib64/librt.so.1 (0x00007feb491ae000)
    libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007feb48e85000)
    /lib64/ld-linux-x86-64.so.2 (0x00007feb4f221000)
    libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007feb48c76000)
    libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007feb48a72000)
    libresolv.so.2 => /lib64/libresolv.so.2 (0x00007feb48858000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007feb48632000)
    libpcre.so.1 => /lib64/libpcre.so.1 (0x00007feb483d1000)
    liblzma.so.5 => /lib64/liblzma.so.5 (0x00007feb481ab000)

Ubuntu 環境下Gtk與QT編譯環境安裝與配置

Linux系統下QT環境搭建

Ubuntu下QT控制台程式無法啟動並執行解決方案以及XTerm的配置方法

Ubuntu 10.04下QT4.7.4移植詳解

Ubuntu 14.04下安裝部署Qt5開發環境

Qt 的詳細介紹:請點這裡
Qt 的:請點這裡

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.