Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Mysql driver linking to unproper libmysqlclient version



  • I'm trying to build the qt mysql driver in order to use libmysqlclient.20 in Xubuntu 16.04. I have:

    Mysql server 5.7 installed
    Qt 5.6.3 installed in /opt

    When running locate libmysqlclient that's the result:

    locate libmysqlclient
    /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
    /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20.3.9
    /usr/share/doc/libmysqlclient20
    /usr/share/doc/libmysqlclient20/NEWS.Debian.gz
    /usr/share/doc/libmysqlclient20/changelog.Debian.gz
    /usr/share/doc/libmysqlclient20/copyright
    /var/lib/dpkg/info/libmysqlclient20:amd64.list
    /var/lib/dpkg/info/libmysqlclient20:amd64.md5sums
    /var/lib/dpkg/info/libmysqlclient20:amd64.shlibs
    /var/lib/dpkg/info/libmysqlclient20:amd64.symbols
    /var/lib/dpkg/info/libmysqlclient20:amd64.triggers
    

    So I need to use the version 20. I run the mysql config command in order to retrieve library locations:

    /usr/bin/mysql_config 
    Usage: /usr/bin/mysql_config [OPTIONS]
    Compiler: GNU 5.4.0
    Options:
            --cflags         [-I/usr/include/mysql ]
            --cxxflags       [-I/usr/include/mysql ]
            --include        [-I/usr/include/mysql]
            --libs           [-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl]
            --libs_r         [-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl]
            --plugindir      [/usr/lib/mysql/plugin]
            --socket         [/var/run/mysqld/mysqld.sock]
            --port           [0]
            --version        [5.7.22]
            --libmysqld-libs [-L/usr/lib/x86_64-linux-gnu -lmysqld -lpthread -lz -lm -lrt -lcrypt -ldl -laio -llz4 -lnuma]
            --variable=VAR   VAR is one of:
                    pkgincludedir [/usr/include/mysql]
                    pkglibdir     [/usr/lib/x86_64-linux-gnu]
                    plugindir     [/usr/lib/mysql/plugin]
    

    Now I go to build the plugin manually. I type:

    cd /opt/Qt5.6.3/5.6.3/Src/qtbase/src/plugins/sqldrivers/mysql
    sudo /opt/Qt5.6.3/5.6.3/gcc_64/bin/qmake "INCLUDEPATH+=-I/usr/include/mysql" "LIBS+=-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl" mysql.pro
    sudo make

    And this is the output:

    g++ -Wl,--no-undefined -Wl,-O1 -Wl,--enable-new-dtags -Wl,-z,origin -Wl,-rpath,\$ORIGIN/../../lib -Wl,-rpath,\$ORIGIN/../../lib -shared -o libqsqlmysql.so .obj/main.o .obj/qsql_mysql.o .obj/moc_qsql_mysql_p.o  -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lrt -ldl -L/usr/lib64/mysql -lmysqlclient_r -lz -lcrypt -lnsl -lm -lssl -lcrypto -L/opt/Qt5.6.3/5.6.3/gcc_64/lib -lQt5Sql -lQt5Core -lpthread  
    mv -f libqsqlmysql.so ../../../../plugins/sqldrivers/
    

    Everything seems to be ok, but when I test the library dependencies in the generated file, I find that is trying to link against the version 18 of the libmysqlclientlibrary:

    ldd /opt/Qt5.6.3/5.6.3/Src/qtbase/plugins/sqldrivers/libqsqlmysql.so
    	linux-vdso.so.1 =>  (0x00007fff1610e000)
    	libmysqlclient.so.18 => not found
    	libQt5Sql.so.5 => not found
    	libQt5Core.so.5 => not found
    	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f27b7429000)
    	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f27b705f000)
    	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f27b6d56000)
    	/lib64/ld-linux-x86-64.so.2 (0x00007f27b79bd000)
    	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f27b6b40000)
    

    What am I missing? Could it be because of the mysql libs installed in user directory and qt located in /opt?



  • Everything was caused by a mess in the system. Lampp was used before installing just Mysql and Xubuntu was in some way keeping caches to that lampp libs which were libmysqlclient.18. The solution has been to uninstall all the mysql stuff and run sudo apt-get autoremove. Then, after having done updatedb to update caches, we reinstall the libmysqlclient package. As libmysqlclient.20 doesn't provide a _r symlink, we need to create it manually:

    cd /usr/lib/x86_64-linux-gnu/
    ln -s libmysqlclient.so libmysqlclient_r.so
    

    And rebuild the plugin with:

    cd /opt/Qt5.6.3/5.6.3/Src/qtbase/src/plugins/sqldrivers/mysql/
    sudo /opt/Qt5.6.3/5.6.3/gcc_64/bin/qmake  "INCLUDEPATH+=-I/usr/include/mysql" "LIBS+=-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl" mysql.pro
    

  • Lifetime Qt Champion

    Hi,

    Glad you found out and thanks for sharing !

    Did you also installed the MySQL client dev package ? If not, it might explain the missing symlink you had.


Log in to reply