How to setup MySQL with MSVC in Qt?



  • Hello guys!
    I want to setup MySQL with MSVC in Qt but without success!
    The problem is when I want to build MySQL driver via Qt 5.13.1 (MSVC 2017 b4-bit) console, it gives me error!
    I enter following commands:

    cd F:\Softwares\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers
    
    qmake MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"
    
    nmake sub-mysql
    

    After running last command I get this error:

    Microsoft (R) Program Maintenance Utility Version 14.16.27034.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            cd mysql\ && ( if not exist Makefile F:\Softwares\Qt\5.13.1\msvc2017_64\bin\qmake.exe -o Makefile F:\Softwares\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers\mysql\mysql.pro "MYSQL_INCDIR=C:\Program Files\MySQL\MySQL Server 8.0\include" "MYSQL_LIBDIR=C:\Program Files\MySQL\MySQL Server 8.0\lib" ) && c:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\X64\nmake.exe -f Makefile
    
    Microsoft (R) Program Maintenance Utility Version 14.16.27034.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            c:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\X64\nmake.exe -f Makefile.Release all
    
    Microsoft (R) Program Maintenance Utility Version 14.16.27034.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    NMAKE : fatal error U1073: don't know how to make 'C:/Program\'
    Stop.
    NMAKE : fatal error U1077: 'c:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\X64\nmake.exe' : return code '0x2'
    Stop.
    NMAKE : fatal error U1077: 'cd' : return code '0x2'
    Stop.
    

    I used short path but problem isn't solve yet!
    Can anyone help me to build MySQL via MSVC for Qt?
    Really thanks!



  • Can anyone help me?
    I still can't solve it!



  • @Nima-Ghorab
    I don't know anything about how these various "make"s work. But from error message

    NMAKE : fatal error U1073: don't know how to make 'C:/Program\'

    something somewhere is being passed a path to C:/Program Files ... which is not being quoted (it has a space in it), and that looks like the cause of the problem. As a separate matter there is a mix of forward slashes & backward slashes, and the \ shown at the end of the error message might also indicate some problem....



  • Dear @JonB Thank you so much!
    I used short path: 'c:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\X64\nmake.exe'
    Which it doesn't contain any spaces but still I tells that path contains spaces!
    How can I fix this?


  • Lifetime Qt Champion

    Hi,

    Do the same for the MySQL path. Or if you can, put it directly in a path without spaces.



  • Dear @SGaist I pass MySQL as double quotes: "MYSQL_INCDIR=C:\Program Files\MySQL\MySQL Server 8.0\include" "MYSQL_LIBDIR=C:\Program Files\MySQL\MySQL Server 8.0\lib"
    But it is still not working!



  • @Nima-Ghorab
    Because of the error message, it won't be on one of your short paths, it will be somewhere that something like Program Files is still being used. And it will be some complicated quoting issue (even though you quote it, believe me, it will get unquoted somewhere...).

    The error is during nmake. You might look through all your Makefiles and see if you can spot that string somewhere....

    Or, because of your command line and the distinct possibility that it's something to do with the long path you have there, go find the short (no-spaces) paths to C:\Program Files\MySQL\MySQL Server 8.0\include and ...\lib, and try specifying those in the first place, see if that gets rid of the error?



  • @JonB and @SGaist Thank you for your helps so much!
    I try short path for MySQL too but it is not working yet!

    F:\Softwares\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers>qmake MYSQL_INCDIR=c:\PROGRA~1\MySQL\MYSQLS~1.0\include MYSQL_LIBDIR=c:\PROGRA~1\MySQL\MYSQLS~1.0\lib
    
    F:\Softwares\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers>nmake sub-mysql
    
    Microsoft (R) Program Maintenance Utility Version 14.16.27034.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            cd mysql\ && ( if not exist Makefile F:\Softwares\Qt\5.13.1\msvc2017_64\bin\qmake.exe -o Makefile F:\Softwares\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers\mysql\mysql.pro "MYSQL_INCDIR=c:\PROGRA~1\MySQL\MYSQLS~1.0\include" "MYSQL_LIBDIR=c:\PROGRA~1\MySQL\MYSQLS~1.0\lib" ) && c:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\X64\nmake.exe -f Makefile
    
    Microsoft (R) Program Maintenance Utility Version 14.16.27034.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            c:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\X64\nmake.exe -f Makefile.Release all
    
    Microsoft (R) Program Maintenance Utility Version 14.16.27034.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    NMAKE : fatal error U1073: don't know how to make 'C:/Program\'
    Stop.
    NMAKE : fatal error U1077: 'c:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\X64\nmake.exe' : return code '0x2'
    Stop.
    NMAKE : fatal error U1077: 'cd' : return code '0x2'
    Stop.
    

    What can I do now?



  • @Nima-Ghorab
    Other than asking @SGaist again, as I know nothing about this make process: it looks like the error comes during the "secondary" nmake invoked from
    c:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\X64\nmake.exe -f Makefile.Release all
    I would find which directory that takes place in, and look through its Makefile.Release file for anything it (or anything it "includes" (!include), and anything it references via $(SOMETHING) macros) for the string Program?

    Also, running nmake /d /p prints extra information about what it;s doing, from which you might be able to figure where the issue is. If you change your nmake command lines to include those options it would be good. Since I don't use qmake or nmake you'd have to find out how to do that, or someone here might be able to tell you.



  • Dear @JonB I am working on what you and @SGaist said...
    Yes the problem was in Makefile.Release!
    So after cleaning every file which generated with qmake command I can't find MySQL library even I address both include and lib folder in short form:

    F:\Softwares\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR=c:\PROGRA~1\MySQL\MYSQLS~1.0\include MYSQL_LIBDIR=c:\PROGRA~1\MySQL\MYSQLS~1.0\lib
    Info: creating stash file F:\Softwares\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers\.qmake.stash
    
    Running configuration tests...
    Checking for DB2 (IBM)... no
    Checking for InterBase... no
    Checking for MySQL... no
    Checking for OCI (Oracle)... no
    Checking for ODBC... no
    Checking for PostgreSQL... no
    Checking for SQLite (version 2)... no
    Checking for TDS (Sybase)... no
    Done running configuration tests.
    
    Configure summary:
    
    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
    
    Qt is now configured for building. Just run 'nmake'.
    Once everything is built, you must run 'nmake install'.
    Qt will be installed into 'F:\Softwares\Qt\5.13.1\msvc2017_64'.
    
    Prior to reconfiguration, make sure you remove any leftovers from
    the previous build.
    

    Whatever I did it just tells MySQL .... no!
    If I use MinGW command line it will find it without any problem but in case of using MSVC this error happens!
    Can you point me to right direction?
    Thank you so much!


  • Qt Champions 2018

    @Nima-Ghorab said in How to setup MySQL with MSVC in Qt?:

    Can you point me to right direction?

    Please check the configure log file - you will find there the information why MySQL wasn't enabled (probably missing MySQL client libraries and header files).



  • Dear @jsulm really thanks!
    here is the log file:

    Command line: "MYSQL_INCDIR=c:\PROGRA~1\MySQL\MYSQLS~1.0\include" "MYSQL_LIBDIR=c:\PROGRA~1\MySQL\MYSQLS~1.0\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 ...
    None of [db2cli.lib] 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 ...
    None of [gds32_ms.lib] 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 F:\Softwares\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && F:\Softwares\Qt\5.13.1\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 = c:\\PROGRA~1\\MySQL\\MYSQLS~1.0\\lib/libmysql.lib" "QMAKE_INCDIR_MYSQL = c:\\PROGRA~1\\MySQL\\MYSQLS~1.0\\include" F:/Softwares/Qt/5.13.1/Src/qtbase/src/plugins/sqldrivers/config.tests/mysql
    > Info: creating stash file F:\Softwares\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers\config.tests\.qmake.stash
    + cd /d F:\Softwares\Qt\5.13.1\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && set MAKEFLAGS=& nmake
    > Microsoft (R) Program Maintenance Utility Version 14.16.27034.0
    > Copyright (C) Microsoft Corporation.  All rights reserved.
    > 	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -W0 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DNDEBUG -I. -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.7.25-winx64\include -IC:\Utils\postgresql\pgsql\include -Ic:\PROGRA~1\MySQL\MYSQLS~1.0\include -IF:\Softwares\Qt\5.13.1\msvc2017_64\mkspecs\win32-msvc -Fo @C:\Users\Nima\AppData\Local\Temp\nm359E.tmp
    > main.cpp
    > .\main.cpp(3): fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
    > NMAKE : fatal error U1077: 'c:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\X64\cl.EXE' : return code '0x2'
    > Stop.
     => 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 ...
    None of [oci.lib] 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 ...
    None of [odbc32.lib] 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 ...
    None of [libpq.lib] found in [] and global paths.
    None of [ws2_32.lib] found in [] and global paths.
    None of [advapi32.lib] 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 ...
    None of [sqlite.lib] 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 ...
    None of [NTWDBLIB.lib] found in [] and global paths.
      => source produced no result.
    Trying source 1 (type sybaseEnv) of library tds ...
      => source failed condition '!config.win32'.
    test config.sqldrivers.libraries.tds FAILED
    

    I now see the errors but I don't know how can I fix these errors!
    Any help would be greatly appreciated!


  • Lifetime Qt Champion

    Not finding windows.h ? That's pretty surprising.
    How did you setup that command prompt before trying to build the plugin ?



  • Dear @SGaist I used Qt 5.13.1 (MSVC 2017 64-bit) console.
    It can't find 64-bit MSVC compiler on my machine so I have to add it in path environment variable.
    And know it just can't find header files and I have to add all include folders in include environment variable.
    In Qt creator IDE I don't have any problem with MSVCs at all but in the case of consoles I don't know why it can't find MSVCs on my machine!
    I installed Microsoft Build Tools 2017 - 15.9.16 version in default location C:\Program File (x86)...


  • Lifetime Qt Champion

    Usually you either have somewhere shortcuts that will start a command prompt with the Visual Studio setup done for you. See here for information about that.



  • Dear @SGaist after I used Microsoft default command line instead of Qt console everything compile successfully with out any errors.
    God bless you and everyone which helped me!


  • Lifetime Qt Champion

    Great !

    Happy coding ! :-)


Log in to reply