Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Library 'mysql' is not defined
QtWS25 Last Chance

Library 'mysql' is not defined

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 6 Posters 7.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H hobbyProgrammer
    27 Nov 2019, 09:02

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

    K Offline
    K Offline
    kshegunov
    Moderators
    wrote on 27 Nov 2019, 09:08 last edited by kshegunov
    #7

    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.

    Read and abide by the Qt Code of Conduct

    H 1 Reply Last reply 27 Nov 2019, 10:26
    2
    • K kshegunov
      27 Nov 2019, 09:08

      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.

      H Offline
      H Offline
      hobbyProgrammer
      wrote on 27 Nov 2019, 10:26 last edited by
      #8

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 27 Nov 2019, 10:36 last edited by
        #9

        Hi,

        Looks like you are following the old instructions.

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        H 1 Reply Last reply 27 Nov 2019, 10:40
        0
        • S SGaist
          27 Nov 2019, 10:36

          Hi,

          Looks like you are following the old instructions.

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

          H Offline
          H Offline
          hobbyProgrammer
          wrote on 27 Nov 2019, 10:40 last edited by hobbyProgrammer
          #10

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 27 Nov 2019, 10:55 last edited by
            #11

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            H 2 Replies Last reply 27 Nov 2019, 10:59
            0
            • S SGaist
              27 Nov 2019, 10:55

              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.

              H Offline
              H Offline
              hobbyProgrammer
              wrote on 27 Nov 2019, 10:59 last edited by
              #12

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

              H 1 Reply Last reply 27 Nov 2019, 11:00
              0
              • H hobbyProgrammer
                27 Nov 2019, 10:59

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

                H Offline
                H Offline
                hobbyProgrammer
                wrote on 27 Nov 2019, 11:00 last edited by
                #13
                This post is deleted!
                H 1 Reply Last reply 27 Nov 2019, 11:03
                0
                • H hobbyProgrammer
                  27 Nov 2019, 11:00

                  This post is deleted!

                  H Offline
                  H Offline
                  hobbyProgrammer
                  wrote on 27 Nov 2019, 11:03 last edited by
                  #14
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • S SGaist
                    27 Nov 2019, 10:55

                    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.

                    H Offline
                    H Offline
                    hobbyProgrammer
                    wrote on 4 Dec 2019, 10:54 last edited by hobbyProgrammer 12 Apr 2019, 10:54
                    #15

                    @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.
                    
                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 4 Dec 2019, 19:45 last edited by
                      #16

                      You still have typos in your paths.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      H 1 Reply Last reply 5 Dec 2019, 07:55
                      1
                      • S SGaist
                        4 Dec 2019, 19:45

                        You still have typos in your paths.

                        H Offline
                        H Offline
                        hobbyProgrammer
                        wrote on 5 Dec 2019, 07:55 last edited by
                        #17

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

                        J 1 Reply Last reply 5 Dec 2019, 08:16
                        0
                        • H hobbyProgrammer
                          5 Dec 2019, 07:55

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

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 5 Dec 2019, 08:16 last edited by
                          #18

                          @hobbyProgrammer Please check better what you're writing:

                          MYSQL_INCDIR=:C\MySQL
                          

                          Why is there a : ?

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          H 1 Reply Last reply 5 Dec 2019, 09:58
                          0
                          • J jsulm
                            5 Dec 2019, 08:16

                            @hobbyProgrammer Please check better what you're writing:

                            MYSQL_INCDIR=:C\MySQL
                            

                            Why is there a : ?

                            H Offline
                            H Offline
                            hobbyProgrammer
                            wrote on 5 Dec 2019, 09:58 last edited by
                            #19

                            @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

                            1 Reply Last reply
                            0
                            • C Offline
                              C Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on 5 Dec 2019, 11:27 last edited by
                              #20

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

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              H 1 Reply Last reply 5 Dec 2019, 13:59
                              1
                              • C Christian Ehrlicher
                                5 Dec 2019, 11:27

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

                                H Offline
                                H Offline
                                hobbyProgrammer
                                wrote on 5 Dec 2019, 13:59 last edited by hobbyProgrammer 12 May 2019, 14:04
                                #21

                                @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

                                1 Reply Last reply
                                0
                                • H Offline
                                  H Offline
                                  hobbyProgrammer
                                  wrote on 5 Dec 2019, 14:17 last edited by
                                  #22

                                  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
                                  1 Reply Last reply
                                  1

                                  16/22

                                  4 Dec 2019, 19:45

                                  • Login

                                  • Login or register to search.
                                  16 out of 22
                                  • First post
                                    16/22
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved