Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Mysql not defined when compiling mysql driver

Mysql not defined when compiling mysql driver

Scheduled Pinned Locked Moved Solved Installation and Deployment
39 Posts 3 Posters 5.1k 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.
  • T Offline
    T Offline
    Thombou
    wrote on last edited by
    #1

    Hi there,
    I followed instruction given here https://doc.qt.io/qt-5/sql-driver.html#qmysql.
    I have installed mysql server and in my directories C:\Program Files\MySQL\MySQL Server 8.0\lib I have libmysql.lib and libmysql.dll. In C:\Program Files\MySQL\MySQL Server 8.0\include, I have mysql.h.

    However when compiling, I get the error Project error: Library 'mysql'not defined.

    C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers\mysql>qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"
    Project ERROR: Library 'mysql' is not defined.

    Any idea to fix this?
    Thanks
    Thombou

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MEMekaniske
      wrote on last edited by MEMekaniske
      #2

      Good evening :)

      Might be some issues with your path, because of spaces.
      What if you copy the include and lib (or the entire content of mysql-server) folders to c:\MySQL\

      then clean/remove build config files and run again
      qmake -- MYSQL_INCDIR=c:\MySQL\include MYSQL_LIBDIR=c:\MySQL\lib

      edit/addon:
      also, you should try running qmake from the sqldrivers dir and not inside mysql

      1 Reply Last reply
      1
      • T Offline
        T Offline
        Thombou
        wrote on last edited by
        #3

        Hi!
        Thanks for the tip. I manage to do the build and install (without errors) but I have the error QMYSQL driver not loaded in my project.
        Did I miss a step somewhere?
        How to check if the plugin is correctly installed?
        Thanks!

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MEMekaniske
          wrote on last edited by MEMekaniske
          #4

          There could be a linking failure somewhere, or it was built in a different environment than you are building the project in.

          Go into the project build directory, something like this if using qt-creator to build:
          build-ProjectName-Desktop_Qt_5_14_0_MinGW_64_bit-Release (for release)
          build-ProjectName-Desktop_Qt_5_14_0_MinGW_64_bit-Debug (for debug)

          then create a folder named sqldrivers and add the created qsqlmysql.dll to it.

          and then in the release or debug folder add the libmysql.dll file there.

          that should work.

          I got a list under the QMYSQL driver not loaded in the application output view when calling db.open(); when I had to do this.
          Think i have seen a call to check availiable drivers too, but I cant remember it now, will try to check

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MEMekaniske
            wrote on last edited by
            #5

            When i run this:

            #include <QSqlDatabase>
            #include <QSqlError>
            #include <QSqlQuery>

               
            
                QSqlDatabase db = QSqlDatabase::addDatabase("QNAMATATA");
                db.setHostName("localhost");
                db.setPort(3306);
                db.setDatabaseName("dbname");
                db.setUserName("root");
                db.setPassword("password");
                bool dbOpen = db.open();
                if(!dbOpen) {
                    qDebug() << "Connection Failure - Error:";
                    qDebug() << dbOpen;
                    qDebug() << db.lastError().text();
                }else {
                    qDebug() << dbOpen;
                    qDebug() << "Connection Success";
                }
            

            I get this output

            QSqlDatabase: QNAMATATA driver not loaded
            QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7 QMYSQL QMYSQL3
            Connection Failure - Error:
            false
            "Driver not loaded Driver not loaded"
            

            So if you try my code with your db info, and change QNAMATATA to QMYSQL, you should see some failure or success messages :)

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Thombou
              wrote on last edited by
              #6

              Hi again
              I tried it and still I have an error. Actually I am not sur the installation went smoothly.
              When i run the qmake command I have the following output

              Qt Sql Drivers:
              DB2 (IBM) .............................. no
              InterBase .............................. no
              MySql .................................. no
              OCI (Oracle) ........................... no
              ODBC ................................... no
              PostgreSQL ............................. no
              SQLite2 ................................ no
              SQLite ................................. yes
              Using system provided SQLite ......... no
              TDS (Sybase) ........................... no

              Then, when I run nmake sub-mysql, I have the following error NMAKE : fatal error U1073: don't know how to make 'sub-mysql'.

              However in C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers I see the files (qsqlmysql.dll, qsqlmysql.lib qsqlmysqld.dll). If I have those files, does it mean that I have successfully installed the plugin?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MEMekaniske
                wrote on last edited by MEMekaniske
                #7

                If you have those files you "have" the plugin, those are the files that needs to be put in a folder named sqldrivers in your project build folder.

                the file qsqlmysqld.dll has a "d" at the end, so that is for the folder with Debug at the end, and the qsqlmysql.dll goes into the one with Release at the end. you should also be able to find the file named libmysql.dll somewhere and that goes into the release and debug folders (top directory of the newly created sqldrivers directory)

                also remember to put

                QT += sql 
                

                in your project file.

                found a call that lets you check if the driver is availiable

                
                    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); //just so we don't get any other errors..
                    qDebug() << db.isDriverAvailable("QMYSQL");
                
                1 Reply Last reply
                1
                • T Offline
                  T Offline
                  Thombou
                  wrote on last edited by
                  #8

                  Your call returns true (which is a good sign). But still, I get the same error (my driver is not loaded...
                  In my .pro file, I have the QT += SQL, and I tried to put the sqldrivers folder at those 2 locations:
                  build-XXX-project-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug\debug\sqldrivers and build-XXX-project-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug\sqldrivers

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MEMekaniske
                    wrote on last edited by MEMekaniske
                    #9

                    Yeah that is good :)

                    Have you placed the libmysql.dll copy from the mysql server into this directory?
                    build-XXX-project-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug\debug\

                    if no copy was created, try and just copy the one that is in the mysql server folder :)

                    found the function call to list all availiable drivers also, nice to have, though isDriverAvailable works fine

                        QStringList listing = QSqlDatabase::drivers();
                        qDebug() << listing;
                    
                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      Thombou
                      wrote on last edited by
                      #10

                      Yes I did... but same error :(
                      BUt this, doesn't it mean that I have not properly installed the plugin?

                      @Thombou said in Mysql not defined when compiling mysql driver:

                      Qt Sql Drivers:
                      DB2 (IBM) .............................. no
                      InterBase .............................. no
                      MySql .................................. no
                      OCI (Oracle) ........................... no
                      ODBC ................................... no
                      PostgreSQL ............................. no
                      SQLite2 ................................ no
                      SQLite ................................. yes
                      Using system provided SQLite ......... no
                      TDS (Sybase) ........................... no

                      Then, when I run nmake sub-mysql, I have the following error NMAKE : fatal error U1073: don't know how to make 'sub-mysql'.

                      However in C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers I see the files (qsqlmysql.dll, qsqlmysql.lib qsqlmysqld.dll). If I have those files, does it mean that I have successfully installed the plugin?

                      kshegunovK 1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        MEMekaniske
                        wrote on last edited by
                        #11

                        I think it is wierd that you get the dll's if they're not getting installed or are working when adding directly to the debug/release folders..

                        You are using the command prompt for Qt 5.14.2 (MSVC2017_64bit) when running qmake nmake etc?

                        T 1 Reply Last reply
                        0
                        • T Thombou

                          Yes I did... but same error :(
                          BUt this, doesn't it mean that I have not properly installed the plugin?

                          @Thombou said in Mysql not defined when compiling mysql driver:

                          Qt Sql Drivers:
                          DB2 (IBM) .............................. no
                          InterBase .............................. no
                          MySql .................................. no
                          OCI (Oracle) ........................... no
                          ODBC ................................... no
                          PostgreSQL ............................. no
                          SQLite2 ................................ no
                          SQLite ................................. yes
                          Using system provided SQLite ......... no
                          TDS (Sybase) ........................... no

                          Then, when I run nmake sub-mysql, I have the following error NMAKE : fatal error U1073: don't know how to make 'sub-mysql'.

                          However in C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers I see the files (qsqlmysql.dll, qsqlmysql.lib qsqlmysqld.dll). If I have those files, does it mean that I have successfully installed the plugin?

                          kshegunovK Offline
                          kshegunovK Offline
                          kshegunov
                          Moderators
                          wrote on last edited by
                          #12

                          @Thombou said in Mysql not defined when compiling mysql driver:

                          If I have those files, does it mean that I have successfully installed the plugin?

                          No, the plugin files go where the other binaries are in <QTDIR>/plugins/sqldrivers where <QTDIR> is the directory where Qt is installed. After that libmysql.dll must be loadable (which usually means it's going to end up in the %%PATH%%.

                          Run your application with QT_DEBUG_PLUGINS=1 for additional diagnostics on the loading. If it finds the plugin dll but can't load it, it usually means it can't load the mysql client library.

                          Read and abide by the Qt Code of Conduct

                          T 1 Reply Last reply
                          3
                          • M MEMekaniske

                            I think it is wierd that you get the dll's if they're not getting installed or are working when adding directly to the debug/release folders..

                            You are using the command prompt for Qt 5.14.2 (MSVC2017_64bit) when running qmake nmake etc?

                            T Offline
                            T Offline
                            Thombou
                            wrote on last edited by
                            #13

                            @MEMekaniske Yes I am using the Qt 5.14.2 MSVC 2017 64-bits command prompt.

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              MEMekaniske
                              wrote on last edited by
                              #14

                              Ok.. I just copied mine to sqldrivers in release/debug and the libmysql.dll to that top directory.
                              Never got the sources installed in the source version they're built with. But still works for me after copying them as said.

                              Maybe try what kshegunov said with QT_DEBUG_PLUGINS=1
                              before or after you add
                              C:\Program Files\MySQL\MySQL Server 8.0\lib\libmysql.dll to path /environment variables

                              1 Reply Last reply
                              0
                              • kshegunovK kshegunov

                                @Thombou said in Mysql not defined when compiling mysql driver:

                                If I have those files, does it mean that I have successfully installed the plugin?

                                No, the plugin files go where the other binaries are in <QTDIR>/plugins/sqldrivers where <QTDIR> is the directory where Qt is installed. After that libmysql.dll must be loadable (which usually means it's going to end up in the %%PATH%%.

                                Run your application with QT_DEBUG_PLUGINS=1 for additional diagnostics on the loading. If it finds the plugin dll but can't load it, it usually means it can't load the mysql client library.

                                T Offline
                                T Offline
                                Thombou
                                wrote on last edited by Thombou
                                #15

                                @kshegunov Thanks for your help.
                                Let's start from the beginning. I tried to open the mysql plugin project with mysql.pro. In the pro file, I added the path to the inblude and lib folder of my installation of mysql (as recommended by MEMekaniske, I put it under C:/mysql). Then I run the project and this is where I found the dll in the directory C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers.
                                Then I copied them in the directory C:\Qt\5.14.2\msvc2017_64\plugins\sqldrivers.

                                After that, I did the qmake command which gave me the output I showed previously, then nmake and nmake install.

                                Then, I copied in the directory where I have my exe file the lib libmysql.dll. In the .pro file of my project, I only added QT += sql, and in my source file `#include <QtSql>.

                                When I add QT_DEBUG_PLUGIN=1, I don't have more information in my output window...

                                1 Reply Last reply
                                0
                                • T Offline
                                  T Offline
                                  Thombou
                                  wrote on last edited by
                                  #16

                                  I realized that I have an issue. In the command line MSVC 20017, in the path, there is no directory pointing to nmake.exe. It wirked before before in my path I had added the path to the other compiler I have on my computer (MinGw) and it was very likely using that one. So I suppose I need to add the path to the nmake directory. However I have 4 directories where I see nmake. I suppose I shoud use the one in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\Hostx64\x64 ? I also have a folder Hostx86 and a x86 subfolder. I am quite lost in what i am doing...

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    MEMekaniske
                                    wrote on last edited by
                                    #17

                                    Are you using visual studio for qt programming or qt creator?

                                    When installing the different qt build platforms, mingw, msvc etc, you also get a command prompt installed with the variables already set for that environment, so if you search start menu for Qt 5.14.2 (MSVC 2017 64-bit) and launch it as administrator that should be the one you work in when building the source version 5.14.2, for a build you are doing with project configuration for MSVC 2017 64-bit and then nmake etc should be working in the correct environment, no matter what paths are set in windows.

                                    1 Reply Last reply
                                    1
                                    • T Offline
                                      T Offline
                                      Thombou
                                      wrote on last edited by Thombou
                                      #18

                                      Ok, I understand that.

                                      I am using QtCreator and I have 2 kits. One for MSVC installed with the visual studio build tools 2019 and the other for mingw.

                                      I already use the dedicated command line for MSVC However, in this command line, I have no nmake
                                      e76a68c5-7291-40f2-a492-308eaecfd316-image.png. Therefore I have run vcvarsall.bat x64.

                                      This is the output of my config.log

                                      Command line: "MYSQL_INCDIR=C:/mysql/include/" "MYSQL_LIBDIR=C:/mysql/lib/"
                                      Global lib dirs: [C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.7.25-winx64\\lib C:\\Utils\\postgresql\\pgsql\\lib] []
                                      Global inc dirs: [C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.7.25-winx64\\include C:\\Utils\\postgresql\\pgsql\\include] []
                                      looking for library db2
                                      Trying source 0 (type inline) of library db2 ...
                                      sqlcli.h not found in [] and global paths.
                                      sqlcli1.h not found in [] and global paths.
                                        => source produced no result.
                                      Trying source 1 (type inline) of library db2 ...
                                        => source failed condition '!config.win32'.
                                      test config.sqldrivers.libraries.db2 FAILED
                                      looking for library ibase
                                      Trying source 0 (type inline) of library ibase ...
                                      ibase.h not found in [] and global paths.
                                        => source produced no result.
                                      Trying source 1 (type inline) of library ibase ...
                                        => source failed condition '!config.win32'.
                                      test config.sqldrivers.libraries.ibase FAILED
                                      looking for library mysql
                                      Trying source 0 (type mysqlConfig) of library mysql ...
                                      mysql_config not found.
                                        => source produced no result.
                                      Trying source 1 (type mysqlConfig) of library mysql ...
                                      mysql_config not found.
                                        => source produced no result.
                                      Trying source 2 (type mysqlConfig) of library mysql ...
                                      mysql_config not found.
                                        => source produced no result.
                                      Trying source 3 (type mysqlConfig) of library mysql ...
                                      mysql_config not found.
                                        => source produced no result.
                                      Trying source 4 (type inline) of library mysql ...
                                        => source failed condition '!config.win32'.
                                      Trying source 5 (type inline) of library mysql ...
                                      + cd /d C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && C:\Qt\5.14.2\msvc2017_64\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.7.25-winx64\\lib C:\\Utils\\postgresql\\pgsql\\lib" "INCLUDEPATH += C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.7.25-winx64\\include C:\\Utils\\postgresql\\pgsql\\include" "QMAKE_USE += mysql" "QMAKE_LIBS_MYSQL = -LC:/mysql/lib/ -llibmysql" "QMAKE_INCDIR_MYSQL = C:/mysql/include/" C:/Qt/5.14.2/Src/qtbase/src/plugins/sqldrivers/config.tests/mysql
                                      > Project ERROR: msvc-version.conf loaded but QMAKE_MSC_VER isn't set
                                       => source failed verification.
                                      Trying source 6 (type inline) of library mysql ...
                                        => source failed condition '!config.win32'.
                                      test config.sqldrivers.libraries.mysql FAILED
                                      looking for library oci
                                      Trying source 0 (type inline) of library oci ...
                                      oci.h not found in [] and global paths.
                                        => source produced no result.
                                      Trying source 1 (type inline) of library oci ...
                                        => source failed condition '!config.win32'.
                                      test config.sqldrivers.libraries.oci FAILED
                                      looking for library odbc
                                      Trying source 0 (type inline) of library odbc ...
                                      sql.h not found in [] and global paths.
                                      sqlext.h not found in [] and global paths.
                                        => source produced no result.
                                      Trying source 1 (type inline) of library odbc ...
                                        => source failed condition 'config.darwin'.
                                      Trying source 2 (type inline) of library odbc ...
                                        => source failed condition '!config.win32 && !config.darwin'.
                                      test config.sqldrivers.libraries.odbc FAILED
                                      looking for library psql
                                      Trying source 0 (type pkgConfig) of library psql ...
                                      pkg-config use disabled globally.
                                        => source produced no result.
                                      Trying source 1 (type psqlConfig) of library psql ...
                                      pg_config not found.
                                        => source produced no result.
                                      Trying source 2 (type psqlEnv) of library psql ...
                                      libpq-fe.h not found in [] and global paths.
                                        => source produced no result.
                                      Trying source 3 (type psqlEnv) of library psql ...
                                        => source failed condition '!config.win32'.
                                      test config.sqldrivers.libraries.psql FAILED
                                      looking for library sqlite2
                                      Trying source 0 (type inline) of library sqlite2 ...
                                      sqlite.h not found in [] and global paths.
                                        => source produced no result.
                                      test config.sqldrivers.libraries.sqlite2 FAILED
                                      looking for library tds
                                      Trying source 0 (type sybaseEnv) of library tds ...
                                      + cd /d C:\Qt\5.14.2\Src\qtbase\src\plugins\sqldrivers\config.tests\tds && C:\Qt\5.14.2\msvc2017_64\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.7.25-winx64\\lib C:\\Utils\\postgresql\\pgsql\\lib" "INCLUDEPATH += C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.7.25-winx64\\include C:\\Utils\\postgresql\\pgsql\\include" "QMAKE_USE += tds" "QMAKE_LIBS_TDS = -lNTWDBLIB" C:/Qt/5.14.2/Src/qtbase/src/plugins/sqldrivers/config.tests/tds
                                      > Project ERROR: msvc-version.conf loaded but QMAKE_MSC_VER isn't set
                                       => source failed verification.
                                      Trying source 1 (type sybaseEnv) of library tds ...
                                        => source failed condition '!config.win32'.
                                      test config.sqldrivers.libraries.tds FAILED
                                      
                                      
                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        MEMekaniske
                                        wrote on last edited by
                                        #19

                                        Ok.

                                        There is a environment setup quide for QT MSCV here:
                                        https://wiki.qt.io/Building_Qt_Desktop_for_Windows_with_MSVC

                                        Tells you to create a bat file with your environment settings,
                                        There is also a lot you probably do not need to have in here, so just modify to fit your needs, or re-install the qt build kits..

                                        @ECHO OFF
                                        
                                        set DEV=C:set QTDIR=%DEV%set PATH=%SystemRoot%;%SystemRoot%32;%QTDIR%
                                        
                                        echo Setting OpenSSL Env.
                                        set OPENSSL=%DEV%set PATH=%OPENSSL%;%PATH%
                                        set LIB=%OPENSSL%set INCLUDE=%OPENSSL%
                                        
                                        echo Setting NASM Env.
                                        set PATH=%DEV%;%PATH%
                                        
                                        echo Setting DirectX Env.
                                        set LIB=%DEV%SDK\Lib\x86;%LIB%
                                        set INCLUDE=%DEV%SDK\Include;%INCLUDE%
                                        
                                        echo Setting Windows SDK Env.
                                        set WindowsSdkDir=%DEV%7.1 SDK
                                        set PATH=%WindowsSdkDir%;%PATH%
                                        set LIB=%WindowsSdkDir%;%LIB%
                                        set INCLUDE=%WindowsSdkDir%;%INCLUDE%
                                        set TARGET_CPU=x86
                                        
                                        echo Setting MSVC2010 Env.
                                        set VSINSTALLDIR=%DEV%set VCINSTALLDIR=%DEV%set DevEnvDir=%VSINSTALLDIR%7\IDE
                                        set PATH=%VCINSTALLDIR%;%VSINSTALLDIR%7\Tools;%VSINSTALLDIR%7\IDE;%VCINSTALLDIR%;%PATH%
                                        set INCLUDE=%VCINSTALLDIR%;%INCLUDE%
                                        set LIB=%VCINSTALLDIR%;%LIB%
                                        set LIBPATH=%VCINSTALLDIR%
                                        
                                        echo Setting Framework Env.
                                        set FrameworkVersion=v4.0.30319
                                        set Framework35Version=v3.5
                                        set FrameworkDir=%SystemRoot%.NET\Framework
                                        set LIBPATH=%FrameworkDir%amp;#37;FrameworkVersion%;%FrameworkDir%amp;#37;Framework35Version%;%LIBPATH%
                                        set PATH=%LIBPATH%;%PATH%
                                        
                                        echo Env. ready.
                                        
                                        title Qt Framework 4.7.1 Development Kit.
                                        
                                        cd %DEV%
                                        
                                        1 Reply Last reply
                                        0
                                        • T Offline
                                          T Offline
                                          Thombou
                                          wrote on last edited by
                                          #20

                                          I have added the path to vcvarsall.bat in my path and I ran the command bcvarsall.bat amd64. After this, I have nmake in my path so that's ok.

                                          I deleted the source component and I am making a fresh install now. I will start the compilation of the plugin after that.

                                          1 Reply Last reply
                                          0

                                          • Login

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