Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Library 'mysql' is not defined

    General and Desktop
    6
    22
    5432
    Loading More Posts
    • 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 last edited by hobbyProgrammer

      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.

      JonB kshegunov 2 Replies Last reply Reply Quote 0
      • H
        hobbyProgrammer last edited by

        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 Reply Quote 1
        • JonB
          JonB @hobbyProgrammer last edited by JonB

          @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?

          H 1 Reply Last reply Reply Quote 0
          • H
            hobbyProgrammer @JonB last edited by

            @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.

            1 Reply Last reply Reply Quote 0
            • kshegunov
              kshegunov Moderators @hobbyProgrammer last edited by

              @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
              

              Read and abide by the Qt Code of Conduct

              H 1 Reply Last reply Reply Quote 0
              • H
                hobbyProgrammer @kshegunov last edited by

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

                kshegunov 1 Reply Last reply Reply Quote 0
                • H
                  hobbyProgrammer last edited by

                  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.

                  1 Reply Last reply Reply Quote 0
                  • kshegunov
                    kshegunov Moderators @hobbyProgrammer last edited by kshegunov

                    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 Reply Quote 2
                    • H
                      hobbyProgrammer @kshegunov last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • SGaist
                        SGaist Lifetime Qt Champion last edited by

                        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 Reply Quote 0
                        • H
                          hobbyProgrammer @SGaist last edited by hobbyProgrammer

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

                          1 Reply Last reply Reply Quote 0
                          • SGaist
                            SGaist Lifetime Qt Champion last edited by

                            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 Reply Quote 0
                            • H
                              hobbyProgrammer @SGaist last edited by

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

                              H 1 Reply Last reply Reply Quote 0
                              • H
                                hobbyProgrammer @hobbyProgrammer last edited by

                                This post is deleted!
                                H 1 Reply Last reply Reply Quote 0
                                • H
                                  hobbyProgrammer @hobbyProgrammer last edited by

                                  This post is deleted!
                                  1 Reply Last reply Reply Quote 0
                                  • H
                                    hobbyProgrammer @SGaist last edited by hobbyProgrammer

                                    @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 Reply Quote 0
                                    • SGaist
                                      SGaist Lifetime Qt Champion last edited by

                                      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 Reply Quote 1
                                      • H
                                        hobbyProgrammer @SGaist last edited by

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

                                        jsulm 1 Reply Last reply Reply Quote 0
                                        • jsulm
                                          jsulm Lifetime Qt Champion @hobbyProgrammer last edited by

                                          @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 Reply Quote 0
                                          • H
                                            hobbyProgrammer @jsulm last edited by

                                            @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 Reply Quote 0
                                            • Christian Ehrlicher
                                              Christian Ehrlicher Lifetime Qt Champion last edited by

                                              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 Reply Quote 1
                                              • First post
                                                Last post