Qt World Summit: Submit your Presentation

issues with building QMYSQL plugin

  • Hi, all -

    My latest adventure is trying to build the QMYSQL plugin. I've tried it from the command line as well as using Creator, and am having issues with both.

    When I issue this command:

    sudo qmake "INCLUDEPATH+=/usr/src/mysql/mysql-5.7.17/include" "LIBS+=-L/usr/lib/x86_64-linux-gnu -lmysqlclient_r" mysql.pro

    I get the following:

    /opt/Qt/5.8/Src/qtbase/src/plugins/sqldrivers/qsqldriverbase.pri:4: Unable to find file for inclusion qt_plugin
    Project MESSAGE: Warning: unknown QT: core-private
    Project MESSAGE: Warning: unknown QT: sql-private

    It might be noteworthy that I don't have a file named mysqlclient_r, but I do have one (actually a link) named libmysqlclient_r.so.18. Should I use this instead?

    When I try to use Creator, upon attempting to build, I get this:

    error: unrecognized command line option ‘-std=c++1z’

    which is puzzling, as I cant' find that flag anywhere.

    When I try to run qmake from Creator, I get this:

    error: Cannot touch /mkspecs/modules/qt_plugin_qsqlmysql.pri: Operation not permitted.

    Which leads me to believe that some Qt variables aren't defined.

    Anyway, I'm fairly lost at this point. Can someone please give me an idea of where I lost my way on this?


  • Lifetime Qt Champion


    You are likely using the wrong qmake. Use the full path to your Qt 5.8 qmake.

    Also since you installed Qt in /opt, your user likely doesn't have the permission to write in that folder.

  • You are likely using the wrong qmake. Use the full path to your Qt 5.8 qmake.

    Aargh...someday, I will remember that you've told me this multiple times.

    The correct qmake worked. Now when I run make, I'm getting that compiler flag error. I looked in my Makefile and see this line:

    CXXFLAGS      = -pipe -O2 -std=c++1z ...

    So, I'm curious...why am I getting this inclusion now? And, what would you recommend I do about it.

    Also, about installing Qt into /opt...where is the appropriate location for it when installing on Linux? I'd assume it would go somewhere outside of my userspace, right? So that it could be shared if there were multiple users?

    Thanks, SGaist.

  • Lifetime Qt Champion

    That's the right place when you want a shared installed.

    However, you don't need to build the plugin in-place, you can use an out of source build.

    The compiler flags just indicates that it want's to use the latest available standard.

    What error are you getting exactly ?

  • That's pretty much the whole error message on the command line (and in Creator):

    g++: error: unrecognized command line option ‘-std=c++1z’

    Is there some verbose flag I could set to try to get more information? My g++ is also in /usr/bin if that makes a difference.

  • Lifetime Qt Champion

    Which version of gcc is it ?

  • mzimmers@debian:/opt/Qt/5.8/Src/qtbase/src/plugins/sqldrivers/mysql$ g++ -v
    Using built-in specs.
    Target: x86_64-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Debian 4.9.2-10' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --with-arch-32=i586 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
    Thread model: posix
    gcc version 4.9.2 (Debian 4.9.2-10) 

    Oh, I see...it's using the old version that I keep to do cross builds to my BBB, isn't it? How best to handle when you want to keep multiple versions of something?

  • Lifetime Qt Champion

    @mzimmers c++1z is C++17 - your compiler (GCC 4.9) for sure does not support it. You should check the mysql.pro file and change it to c++11.

  • @jsulm thanks for the reply. I recognize that this flag isn't compatible with my current compiler. Of greater concern to me is: where is this flag coming from? It's not in my .pro file, and none of the other projects I've built using Creator have generated this flag.

    I'm looking into upgrading my compiler, but someone on the Debian forum told me that this might not be a good idea, so that's on hold for a bit.

    EDIT: OK, it looks like upgrading my compiler without upgrading the version of Debian I'm running is a bad idea. At this point, it seems like it would be the tail wagging the dog anyway. So, I'm back to this question: where is that flag coming from? Does qmake actually parse the code to the point where it might detect that such a flag would be necessary?

    Question #2: Sgaist referred to "an out of source build" above. I'm not sure I know what this mean -- does it mean redirecting the output of the build to another directory? If so, is this accomplished with a qmake variable? Because I didn't see one in the documentation that looked like it would alter this.


  • Lifetime Qt Champion

    @mzimmers qmake does not parse any source code, it only parses pro files. Can you post that pro file or a link to it? This flag should be in that file. You also should check the output of the qmake command, maybe it gives some hints.
    Out of source simply means that you call qmake and make from a directory outside of the source code you're going to build. This way all the build artefacts are not in the source directory - you keep the source code directory clean.

  • @jsulm here's the project file. I put in the last line myself.

    TARGET = qsqlmysql
    HEADERS += $$PWD/qsql_mysql_p.h
    SOURCES += $$PWD/qsql_mysql.cpp $$PWD/main.cpp
    #QMAKE_USE += mysql
    OTHER_FILES += mysql.json
    QMAKE_CXXFLAGS -= "-std=c++1z"

    I'm still getting this error, though:

    /opt/Qt/5.8/Src/qtbase/mkspecs/features/qt_plugin.prf:62: error: Cannot touch /mkspecs/modules/qt_plugin_qsqlmysql.pri: Operation not permitted.

    It's trying to write to mkspecs as a root directory. I verified this by running as root; it creates a mkspecs root directory. I think the cause is some undefined symbols, as the lines that form this symbol are:

    38    mod_work_pfx = $$MODULE_QMAKE_OUTDIR/mkspecs/modules
    44    MODULE_FWD_PRI = $$mod_work_pfx/qt_plugin_$${MODULE}.pri
    62            touch($$MODULE_FWD_PRI, $$MODULE_PRI)

    Thanks for any assistance.

  • Lifetime Qt Champion

    To avoid losing time, just copy the qtbase module sources in you home folder so you don't have that touch problem.

  • I just tried this; got a few errors. I took care of all but one:

    error: Project has no top-level .qmake.conf file.

    I still think there's something wrong with my variables or symbols if it was trying to write to the root directory, though.

  • Lifetime Qt Champion

    Did you copy the whole qtbase source ?

  • @SGaist oops...I misread what you said above...sorry. I'm still getting this error, though:

    error: Cannot touch /mkspecs/modules/qt_plugin_qsqlmysql.pri: Operation not permitted.

    I can try this with root, too, but I'm pretty sure it will indeed write to a directory /mkspecs...it did before.

  • Lifetime Qt Champion

    The sources likely have kept their rights. You should call something like sudo chown user:group qtbase -R (replace user and group by your user name and main group).

  • User and group IDs are already mine. (They are in the original location as well.)

  • Lifetime Qt Champion

    Then are the files read-only ?

  • @SGaist No, not for me:

    mzimmers@debian:~/QtStuff/qtbase/src/plugins/sqldrivers/mysql$ pwd
    mzimmers@debian:~/QtStuff/qtbase/src/plugins/sqldrivers/mysql$ ls -l
    total 108
    -rw-rw-r-- 1 mzimmers mzimmers  2619 Jan 18 09:20 main.cpp
    -rw-r--r-- 1 mzimmers mzimmers  8229 Mar 15 20:04 Makefile
    -rw-rw-r-- 1 mzimmers mzimmers    40 Jan 18 09:20 mysql.json
    -rw-rw-r-- 1 mzimmers mzimmers   250 Mar 15 20:06 mysql.pro
    -rw-r--r-- 1 mzimmers mzimmers 23807 Mar 16 17:11 mysql.pro.user
    -rw-rw-r-- 1 mzimmers mzimmers 50811 Jan 18 09:20 qsql_mysql.cpp
    -rw-rw-r-- 1 mzimmers mzimmers  3952 Jan 18 09:20 qsql_mysql_p.h
    -rw-rw-r-- 1 mzimmers mzimmers   204 Jan 18 09:20 README

  • Lifetime Qt Champion

    I just realised there's something fishy with the error message: the path seems to start at the root of the filesystem and doesn't match anything I know from the sources.

    Can you try a clean out of source build of the plugin from the console ?

  • @SGaist I deleted my Makefile and ran the following command:

    mzimmers@debian:~/QtStuff/qtbase/src/plugins/sqldrivers/mysql$ /opt/Qt/5.8/gcc_64/bin/qmake "INCLUDEPATH+=/usr/local/include /usr/src/mysql/mysql-5.7.17/include" "LIBS+=-L/usr/lib -lmysqlclient_r" /home/mzimmers/QtStuff/qtbase/src/plugins/sqldrivers/mysql/mysql.pro

    Question #1: what is the correct syntax for removing a compiler flag? I tried this:

    QMAKE_CXXFLAGS -= "-std=c++1z"

    but that didn't work.

    I then went in and manually modified the Makefile, changing "-std=c++1z" to "-std=c++11", and ran make. I then encountered this error:

    mzimmers@debian:~/QtStuff/qtbase/src/plugins/sqldrivers/mysql$ make
    g++ -c -pipe -O2 -std=c++11 -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wall -W -Wvla -Wdate-time -D_REENTRANT -fPIC -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -isystem /usr/local/include -I/usr/src/mysql/mysql-5.7.17/include -I/opt/Qt/5.8/gcc_64/include/QtSql/5.8.0 -I/opt/Qt/5.8/gcc_64/include/QtSql/5.8.0/QtSql -I/opt/Qt/5.8/gcc_64/include/QtCore/5.8.0 -I/opt/Qt/5.8/gcc_64/include/QtCore/5.8.0/QtCore -I/opt/Qt/5.8/gcc_64/include -I/opt/Qt/5.8/gcc_64/include/QtSql -I/opt/Qt/5.8/gcc_64/include/QtCore -I.moc -I../../../../mkspecs/linux-g++ -o .obj/qsql_mysql.o qsql_mysql.cpp
    In file included from qsql_mysql_p.h:60:0,
                     from qsql_mysql.cpp:40:
    /usr/src/mysql/mysql-5.7.17/include/mysql.h:57:27: fatal error: mysql_version.h: No such file or directory
     #include "mysql_version.h"
    compilation terminated.
    Makefile:834: recipe for target '.obj/qsql_mysql.o' failed
    make: *** [.obj/qsql_mysql.o] Error 1

    I don't have a file named mysql_version.h. I do have a file named mysql_version.h.in. I'm not familiar with .in files, but according to Wiki, it's input to a program called "autoconf." In reading the documentation, I wonder whether I somehow missed a step in the build that converts this .in file into a .h file. EDIT: I did find a cmake file with that name as well, though there's nothing in the documentation about running cmake manually.

    Anyway, we do seem to be moving forward. I would like to resolve this problem with the compiler flag, though.

    Thanks for all the help.

  • Lifetime Qt Champion

    Out of curiosity, why don't you install the MySQL dev package from your distribution ? That would certainly simplify things.

    As for your compiler, which version is it ?

  • MySQL doesn't make a package for Debian. The compiler is 4.9.2. I asked about updating the compiler in a Debian forum, and got a lot of snarky answers telling me it was a bad idea.

  • Lifetime Qt Champion

    Sure there is: see libmysqlclient-dev.

    IIRC 4.9.2 should be good to build Qt 5.

  • @SGaist I'm sorry; I misunderstood you -- when you said "from your distribution," I thought you meant part of the Debian package.

    Just to be clear, are you saying that with that package, I can better build the QMYSQL plugin, or that it's already included?

    And, for my education, I'd really like to know how to alter compiler flags on the command line. I've tried "QMAKE_CXXFLAGS -=" but that doesn't seem to do anything.


  • Lifetime Qt Champion

    It will make things easier to build the plugin.

    IIRC CONFIG += c++11 should only enable C++11 feature and not later.

  • @SGaist I think we're getting closer. I installed the package you referenced above, and ran this qmake command:

    /opt/Qt/5.8/gcc_64/bin/qmake "INCLUDEPATH+=/usr/include" "LIBS+=-L/usr/lib/x86_64-linux-gnu/ -lmysqlclient_r" /home/mzimmers/QtStuff/qtbase/src/plugins/sqldrivers/mysql/mysql.pro/

    I then edited the Makefile, changing the 2 occurrences of "-std=c++1z" to "-std=c++11" and ran make. Here's the output:

    mzimmers@debian:~/QtStuff/qtbase/src/plugins/sqldrivers/mysql$ make
    rm -f libqsqlmysql.so
    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/qsql_mysql.o .obj/main.o .obj/moc_qsql_mysql_p.o  -L/usr/lib -lmysqlclient_r -L/opt/Qt/5.8/gcc_64/lib -lQt5Sql -lQt5Core -L/usr/lib64/mysql -lmysqlclient -lpthread -lz -lm -lssl -lcrypto -ldl  
    /usr/bin/ld: cannot find -lmysqlclient_r
    collect2: error: ld returned 1 exit status
    Makefile:115: recipe for target '../../../../plugins/sqldrivers/libqsqlmysql.so' failed
    make: *** [../../../../plugins/sqldrivers/libqsqlmysql.so] Error 1

    I also tried LIBS+=-L/usr/lib/x86_64-linux-gnu (which is the actual directory) with the same results. Any idea what's wrong here?

    Thank you.

  • Lifetime Qt Champion

    You shouldn't need the -l parameter

  • @SGaist OK, I removed it. Here are the results:

    mzimmers@debian:~/QtStuff/qtbase/src/plugins/sqldrivers/mysql$ /opt/Qt/5.8/gcc_64/bin/qmake "INCLUDEPATH+=/usr/include" "LIBS+=-L/usr/lib/" ./mysql.pro
    mzimmers@debian:~/QtStuff/qtbase/src/plugins/sqldrivers/mysql$ make
    rm -f libqsqlmysql.so
    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/qsql_mysql.o .obj/main.o .obj/moc_qsql_mysql_p.o  -L/usr/lib/ -L/opt/Qt/5.8/gcc_64/lib -lQt5Sql -lQt5Core -L/usr/lib64/mysql -lmysqlclient -lpthread -lz -lm -lssl -lcrypto -ldl  
    /usr/bin/ld: cannot find -lz
    /usr/bin/ld: cannot find -lssl
    /usr/bin/ld: cannot find -lcrypto
    collect2: error: ld returned 1 exit status
    Makefile:115: recipe for target '../../../../plugins/sqldrivers/libqsqlmysql.so' failed
    make: *** [../../../../plugins/sqldrivers/libqsqlmysql.so] Error 1

    I don't know whether this is progress or a step back. Do I need to specify paths for the libraries that make can't find?

    On a more general note: I notice that I seem to be needing to do a lot of things that aren't mentioned on the page that talks about building this plugin. Is the page incomplete, or is there something atypical about my Qt installation?


  • Lifetime Qt Champion

    You need the development packages for OpenSSL and zlib.

    That's rather a side effect of the dependencies of the 3rd party that can change over time.

  • @SGaist so, I need these?


    They aren't explicitly labeled "development packages" but I'm hoping this is what I need...

  • Lifetime Qt Champion

    It seems you are forgetting you are running Linux ;)

    Use your distributions package manager for that like you did to install the MySQL development package.

  • @SGaist believe it or not, I did look there first, but I wasn't sure what to choose. My best guesses would be:

    openssl - Secure Sockets Layer toolkit - cryptographic utility
    zlib1g-dev - compression library - development

    (I found these among the results of an apt-cache search for openssl and zlib.)

    Did I guess well?

  • Lifetime Qt Champion

    Sorry, it's libssl-dev the OpenSSL package is the command line client.
    As for zlib, yes

  • I installed those two, and here is the output:```
    mzimmers@debian:~/QtStuff/qtbase/src/plugins/sqldrivers/mysql$ make
    rm -f libqsqlmysql.so
    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/qsql_mysql.o .obj/main.o .obj/moc_qsql_mysql_p.o -L/usr/lib/x86_64-linux-gnu/ -lmysqlclient_r -L/opt/Qt/5.8/gcc_64/lib -lQt5Sql -lQt5Core -L/usr/lib64/mysql -lmysqlclient -lpthread -lz -lm -lssl -lcrypto -ldl
    /usr/bin/ld: cannot find -lmysqlclient_r
    collect2: error: ld returned 1 exit status
    Makefile:115: recipe for target '../../../../plugins/sqldrivers/libqsqlmysql.so' failed
    make: *** [../../../../plugins/sqldrivers/libqsqlmysql.so] Error 1

    I have a file called "libmysqlclient_r.so.18" in /usr/lib/x86_64-linux-gnu...is this not the library it wants?
    Thanks. I appreciate your staying up so late to help me with this.

  • Lifetime Qt Champion

    It looks like you didn't install the libmysqlclient-dev package.

  • @SGaist yes I did. I just tried again, and apt-get confirmed I'm up to date on this package. And according to the file list on the page you linked, the libraries are in the right location:

    mzimmers@debian:/usr/lib/x86_64-linux-gnu$ pwd
    mzimmers@debian:/usr/lib/x86_64-linux-gnu$ ls libmy*
    libmysqlclient.a        libmysqlclient_r.so.18.0.0  libmysqlclient.so.18      libmysqlclient.so.20      libmysqlservices.a
    libmysqlclient_r.so.18  libmysqlclient.so           libmysqlclient.so.18.0.0  libmysqlclient.so.20.3.4

  • Lifetime Qt Champion

    There's something strange here, you are missing at least the libmysqlclient_r.so symlink in that folder.

  • @SGaist I just did an apt-get remove and another install...same files. Should I file a bug report in the Debian forum?

  • Lifetime Qt Champion

    Since you have two sets of MySQL libraries there might be something else.

    Can you post the result of dpkg -l | grep -i mysql ?

Log in to reply