Important: Please read the 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

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

    Usage: /usr/bin/mysql_config [OPTIONS]
    Compiler: GNU 5.4.0
            --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"
    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 .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 ../../../../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/ =>  (0x00007fff1610e000) => not found => not found => not found => /usr/lib/x86_64-linux-gnu/ (0x00007f27b7429000) => /lib/x86_64-linux-gnu/ (0x00007f27b705f000) => /lib/x86_64-linux-gnu/ (0x00007f27b6d56000)
    	/lib64/ (0x00007f27b79bd000) => /lib/x86_64-linux-gnu/ (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

    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"

  • Lifetime Qt Champion


    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