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

Library 'mysql' is not defined



  • Hi,
    I know that there are a lot of people who already asked almost everything there is about the MySQL driver.
    I think I've tried it all, but I keep getting the message "project ERROR: Library 'mysql' is not defined.

    Is there anyone who can help me?

    I tried to follow the instructions multiple times, but failed every time.
    I use mingw73_32 and Qt 5.13.2

    When I get this error?

    set mysql=C:\\MySQL\\MySQL~Server~5.5
    cd C:\Qt\Qt5.13.2\5.13.2\qtbase\src\plugins\sqldrivers\mysql
    qmake "INCLUDEPATH+=%mysql%\\include" "LIBS+=%mysql%\\lib\\libmysql.lib" -o Makefile mysql.pro
    

    I get:

    Project ERROR: Library 'mysql' is not defined
    

    I had a look around and qtsqldrivers-config.pri is in that directory.



  • This worked for me and I used:

    • OS: Windows
    • Qt version: 5.13.1 and 5.13.2
    • Qt creator: 4.10.1
    • compiler: mingw73_32

    Step by step:

    1. Download msys & msysgit
    2. Open the cmd of msys and type these commands (keep in mind that the second and third command do not contain cd. You need to call the .exe files from the mysql path):
    • cd <path to libmysql.lib>
    • C:/msysgit/mingw/bin/reimp.exe libmysql.lib
    • C:/msysgit/mingw/bin/dlltool.exe -k -d libmysql.def -l libmysql.a
    1. go to the qt cmd called: Qt <version> (<compiler>). Use the one with the mingw32 compiler.
    2. execute the following commands:
    • cd C:/Qt/Qt<version>/<version>/Src/qtbase/src/plugins/sqldrivers
    • qmake sqldrivers.pro
    1. open mysql.pro and make sure that it looks like this (change the include path and the lib path, but make sure that the include path and the depend path are the same!) and save after you finished editing it:
    TARGET = qsqlmysql
    
    HEADERS += $$PWD/qsql_mysql_p.h
    SOURCES += $$PWD/qsql_mysql.cpp $$PWD/main.cpp
    
    #QMAKE_USE += mysql
    LIBS += -L'C:/MySQL/lib/'
    -llibmysql
    
    INCLUDEPATH += 'C:/MySQL/include'
    
    DEPENDPATH += 'C:/MySQL/include'
    
    
    OTHER_FILES += mysql.json
    
    PLUGIN_CLASS_NAME = QMYSQLDriverPlugin
    include(../qsqldriverbase.pri)
    
    
    1. execute the following commands:
    • qmake mysql.pro
    • qmake "INCLUDEPATH+=<includepath>" "LIBS+=<libpath>/libmysql.lib" mysql.pro
    • mingw32-make
    1. go to C:/Qt/Qt<version>/<version>/Src/qtbase/src/plugins/sqldrivers/plugins/sqldrivers in the file explorer. You should see these four files now:
    • qsqlmysql.dll
    • qsqlmysqld.dll
    • qsqlmysql.a
    • qsqlmysqld.a
    1. copy them and place them into: C:/Qt/Qt<version>/<version>/mingw73_32/plugins/sqldrivers


  • @hobbyProgrammer
    I would worry about the first error message, maybe the second is a consequence of it.

    Cannot read C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/qtsqldrivers-config.pri: No such file or directory

    I had a look around and qtsqldrivers-config.pri is in that directory.

    I would investigate this a bit more.

    Otherwise, have you Googled specifically for Project ERROR: Library 'mysql' is not defined, there are a number of hits?



  • @JonB hi, I already fixed the first error, but the second one stays. I also have that one on my laptop (abd computer). For the past 2 weeks I've been googling it, but so far without result.


  • Qt Champions 2017

    @hobbyProgrammer said in Library 'mysql' is not defined:

    qmake "INCLUDEPATH+=%mysql%\include" "LIBS+=%mysql%\lib\libmysql.lib" -o Makefile mysql.pro

    qmake uses $$(...) for environment variables, this isn't cmd, do you should try like this:

    qmake "INCLUDEPATH+=$$(mysql)/\include" "LIBS+=$$(mysql)/lib/libmysql.lib" -o Makefile mysql.pro
    


  • @kshegunov Thanks, but I still get the same error.



  • also whenever i open sqldrivers.pro it gives me the same errors:

    Project ERROR: Could not find feature sql-mysql.
    [Inexact] Project ERROR: Library 'db2' is not defined.
    [Inexact] Project ERROR: Library 'oci' is not defined.
    [Inexact] Project ERROR: Library 'mysql' is not defined.
    [Inexact] Project ERROR: Library 'ibase' is not defined.
    [Inexact] Project ERROR: Library 'psql' is not defined.
    [Inexact] Project ERROR: Library 'odbc' is not defined.
    [Inexact] Project ERROR: Library 'sqlite2' is not defined.
    [Inexact] Project ERROR: Library 'tds' is not defined.


  • Qt Champions 2017

    Why do you have tilde in your path?
    Make sure that you get the correct paths inside the project file (use message() to print them out). Also the qmake run can be made more verbose if you pass -d to it (-d -d for max verbosity).

    also whenever i open sqldrivers.pro it gives me the same errors:

    Well, don't. Not unless you intend to build all the drivers.



  • @kshegunov Hi
    Where exactly do I need to add message()?
    In the main.cpp?


  • Lifetime Qt Champion

    Hi,

    Looks like you are following the old instructions.

    Take a look at the current Qt MySQL driver documentation. The parameters have changed.



  • @SGaist yes, but unfortunately, following the new instructions results in
    Project ERROR: Could not find feature sql-mysql


  • Lifetime Qt Champion

    Based on your first post you are missing two dashes after the qmake call. The example from the documentation shows qmake -- and then the additional stuff. Please try that.



  • @SGaist so like:
    qmake -- MYSQL_INCDIR=:C\MySQL\include "MYSQL_LIBDIR=C:\MySQL\lib"



  • This post is deleted!


  • This post is deleted!


  • @SGaist I tried that, but it still won't work. I also do not get the configuration screen where you can see which drivers are installed. Only when I do mingw32-make I see that it only goes to odbc and sqlite

    C:\Qt\Qt5.13.2\5.13.2\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR=:C\MySQL\include MYSQL_LIBDIR=C:\MySQL\lib
    
    C:\Qt\Qt5.13.2\5.13.2\Src\qtbase\src\plugins\sqldrivers>mingw32-make
    cd odbc\ && ( if not exist Makefile C:\Qt\Qt5.13.2\5.13.2\mingw73_32\bin\qmake.exe -o Makefile C:\Qt\Qt5.13.2\5.13.2\Src\qtbase\src\plugins\sqldrivers\odbc\odbc.pro ) && mingw32-make -f Makefile
    mingw32-make[1]: Entering directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make -f Makefile.Release all
    mingw32-make[2]: Entering directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make[2]: Nothing to be done for 'all'.
    mingw32-make[2]: Leaving directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make -f Makefile.Debug all
    mingw32-make[2]: Entering directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make[2]: Nothing to be done for 'all'.
    mingw32-make[2]: Leaving directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make[1]: Leaving directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/odbc'
    cd sqlite\ && ( if not exist Makefile C:\Qt\Qt5.13.2\5.13.2\mingw73_32\bin\qmake.exe -o Makefile C:\Qt\Qt5.13.2\5.13.2\Src\qtbase\src\plugins\sqldrivers\sqlite\sqlite.pro ) && mingw32-make -f Makefile
    mingw32-make[1]: Entering directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make -f Makefile.Release all
    mingw32-make[2]: Entering directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make[2]: Nothing to be done for 'all'.
    mingw32-make[2]: Leaving directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make -f Makefile.Debug all
    mingw32-make[2]: Entering directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make[2]: Nothing to be done for 'all'.
    mingw32-make[2]: Leaving directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make[1]: Leaving directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/sqlite'
    

    Also this doesn't seem to work:

    C:\Qt\Qt5.13.2\5.13.2\Src\qtbase\src\plugins\sqldrivers>mingw32-make sub-mysql
    mingw32-make: *** No rule to make target 'sub-mysql'.  Stop.
    

  • Lifetime Qt Champion

    You still have typos in your paths.



  • @SGaist in the mysql_incdir/mysql_libdir? or anywhere else?


  • Lifetime Qt Champion

    @hobbyProgrammer Please check better what you're writing:

    MYSQL_INCDIR=:C\MySQL
    

    Why is there a : ?



  • @jsulm hi,

    yes I see. I tried again without the typo but it still didn't work

    C:\Qt\Qt5.13.2\5.13.2\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR=C:\MySQL\include MYSQL_LIBDIR=C:\MySQL\lib
    
    C:\Qt\Qt5.13.2\5.13.2\Src\qtbase\src\plugins\sqldrivers>mingw32-make
    cd odbc\ && ( if not exist Makefile C:\Qt\Qt5.13.2\5.13.2\mingw73_32\bin\qmake.exe -o Makefile C:\Qt\Qt5.13.2\5.13.2\Src\qtbase\src\plugins\sqldrivers\odbc\odbc.pro ) && mingw32-make -f Makefile
    mingw32-make[1]: Entering directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make -f Makefile.Release all
    mingw32-make[2]: Entering directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make[2]: Nothing to be done for 'all'.
    mingw32-make[2]: Leaving directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make -f Makefile.Debug all
    mingw32-make[2]: Entering directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make[2]: Nothing to be done for 'all'.
    mingw32-make[2]: Leaving directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make[1]: Leaving directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/odbc'
    cd sqlite\ && ( if not exist Makefile C:\Qt\Qt5.13.2\5.13.2\mingw73_32\bin\qmake.exe -o Makefile C:\Qt\Qt5.13.2\5.13.2\Src\qtbase\src\plugins\sqldrivers\sqlite\sqlite.pro ) && mingw32-make -f Makefile
    mingw32-make[1]: Entering directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make -f Makefile.Release all
    mingw32-make[2]: Entering directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make[2]: Nothing to be done for 'all'.
    mingw32-make[2]: Leaving directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make -f Makefile.Debug all
    mingw32-make[2]: Entering directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make[2]: Nothing to be done for 'all'.
    mingw32-make[2]: Leaving directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make[1]: Leaving directory 'C:/Qt/Qt5.13.2/5.13.2/Src/qtbase/src/plugins/sqldrivers/sqlite'
    
    

    for some reason it just doesn't go to mysql


  • Lifetime Qt Champion

    Since qmake did not output anything according to your logs you should remove config.cache and start over (already told you above somewhere)



  • @Christian-Ehrlicher alright, I managed to get these files in C:/Qt/Qt5.13.1/5.13.1/Src/qtbase/src/plugins/sqldrivers/plugins/sqldrivers:

    • qsqlmysql.dll
    • qsqlmysqld.dll
    • qsqlmysql.a
    • qsqlmysqld.a

    but for some reason I still get this error:

    build-testDatabaseDrivers-Desktop_Qt_5_13_1_MinGW_64_bit-Debug\debug\testDatabaseDrivers.exe ...
    ("QSQLITE", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
    

    EDIT:

    I copied the .dll files to C:/Qt/Qt<version>/<version>/mingw73_32/plugins/sqldrivers
    and now it works



  • This worked for me and I used:

    • OS: Windows
    • Qt version: 5.13.1 and 5.13.2
    • Qt creator: 4.10.1
    • compiler: mingw73_32

    Step by step:

    1. Download msys & msysgit
    2. Open the cmd of msys and type these commands (keep in mind that the second and third command do not contain cd. You need to call the .exe files from the mysql path):
    • cd <path to libmysql.lib>
    • C:/msysgit/mingw/bin/reimp.exe libmysql.lib
    • C:/msysgit/mingw/bin/dlltool.exe -k -d libmysql.def -l libmysql.a
    1. go to the qt cmd called: Qt <version> (<compiler>). Use the one with the mingw32 compiler.
    2. execute the following commands:
    • cd C:/Qt/Qt<version>/<version>/Src/qtbase/src/plugins/sqldrivers
    • qmake sqldrivers.pro
    1. open mysql.pro and make sure that it looks like this (change the include path and the lib path, but make sure that the include path and the depend path are the same!) and save after you finished editing it:
    TARGET = qsqlmysql
    
    HEADERS += $$PWD/qsql_mysql_p.h
    SOURCES += $$PWD/qsql_mysql.cpp $$PWD/main.cpp
    
    #QMAKE_USE += mysql
    LIBS += -L'C:/MySQL/lib/'
    -llibmysql
    
    INCLUDEPATH += 'C:/MySQL/include'
    
    DEPENDPATH += 'C:/MySQL/include'
    
    
    OTHER_FILES += mysql.json
    
    PLUGIN_CLASS_NAME = QMYSQLDriverPlugin
    include(../qsqldriverbase.pri)
    
    
    1. execute the following commands:
    • qmake mysql.pro
    • qmake "INCLUDEPATH+=<includepath>" "LIBS+=<libpath>/libmysql.lib" mysql.pro
    • mingw32-make
    1. go to C:/Qt/Qt<version>/<version>/Src/qtbase/src/plugins/sqldrivers/plugins/sqldrivers in the file explorer. You should see these four files now:
    • qsqlmysql.dll
    • qsqlmysqld.dll
    • qsqlmysql.a
    • qsqlmysqld.a
    1. copy them and place them into: C:/Qt/Qt<version>/<version>/mingw73_32/plugins/sqldrivers

Log in to reply