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

QMake can't find MySQL



  • Hi there,

    I have been reading the documentation on how to build the MySQL driver. Here is my setup:

    • Windows 10
    • MySQL Server v8.0.18 (64-bit) (installed under "C:\Program Files\MySQL")
    • MySQL Connector C++ v8.0.18 (installed under "C:\Program Files\MySQL")
    • MSVC 2017 (64-bit) to compile
    • QT 5.13.2 w/ Sources, and Debugging Tools for Windows

    Going through the documentation, I am running the following command:

    cd C:\Qt\5.13.2\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"
    

    and the output is:

    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
    

    Is there a way to determine why this is failing? I don't see why it isn't picking up the MySQL libraries.

    Thanks,

    John



  • @jsulm Thanks jsulm, that got it to recognize MySQL! I guess the default developer command prompt within Visual Studio is either the x86 or mixed environment. Just a note, I had to use 'x64 Native Tools Command Prompt for VS 2019' to get it to recognize, the cross tools one wouldn't recognize it.

    That solves this issue specifically, as I get the output needed.

    Thanks everyone for your help.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should have test logs. They will contain the various tests done and why they failed.



  • Thanks SGaist, it appears NMAKE is failing to find windows.h, here is the most relevant log:

    Trying source 5 (type inline) of library mysql ...
    + cd /d C:\Qt\5.13.2\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && C:\Qt\5.13.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 = \"C:/Program Files/MySQL/MySQL Server 8.0/lib/libmysql.lib\"" "QMAKE_INCDIR_MYSQL = \"C:/Program Files/MySQL/MySQL Server 8.0/include\"" C:/Qt/5.13.2/Src/qtbase/src/plugins/sqldrivers/config.tests/mysql
    > Info: creating stash file C:\Qt\5.13.2\Src\qtbase\src\plugins\sqldrivers\config.tests\.qmake.stash
    + cd /d C:\Qt\5.13.2\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && set MAKEFLAGS=& nmake
    > Microsoft (R) Program Maintenance Utility Version 14.00.24210.0
    > Copyright (C) Microsoft Corporation.  All rights reserved.
    > 	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -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 -I"C:\Program Files\MySQL\MySQL Server 8.0\include" -IC:\Qt\5.13.2\msvc2017_64\mkspecs\win32-msvc -Fo @C:\Users\John\AppData\Local\Temp\nm6197.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:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\cl.EXE"' : return code '0x2'
    > Stop.
    

    I googled this and it seems to mean the windows SDK is not being picked up, and I have found a windows.h in "C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um". Should I add that directory to the PATH?


  • Lifetime Qt Champion

    @JohnDog Do you use Visual Studio command prompt?



  • @JohnDog
    A lot of people have failed on build mysql.lib by VS. QT has no a details step for it long time .


  • Lifetime Qt Champion

    @cawlfj said in QMake can't find MySQL:

    QT has no a details step for it long time .

    At least the error above is not Qt's fault - when the compiler can't find windows.h then it was not set up correct...



  • @cawlfj Thanks for the suggestion, I just installed VS Studio 2019. I also deleted the config.cache, .opt, .summary and .log files before running again. After running the following within the VS studio developer command prompt:

    cd C:\Qt\5.13.2\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"
    

    I get the same output where it doesn't see MySQL, and an architecture conflict in the log:

    Trying source 5 (type inline) of library mysql ...
    + cd /d C:\Qt\5.13.2\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && C:\Qt\5.13.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 = \"C:\\Program Files\\MySQL\\MySQL Server 8.0\\lib/libmysql.lib\"" "QMAKE_INCDIR_MYSQL = \"C:\\Program Files\\MySQL\\MySQL Server 8.0\\include\"" C:/Qt/5.13.2/Src/qtbase/src/plugins/sqldrivers/config.tests/mysql
    + cd /d C:\Qt\5.13.2\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && set MAKEFLAGS=& nmake clean && set MAKEFLAGS=& nmake
    > Microsoft (R) Program Maintenance Utility Version 14.23.28107.0
    > Copyright (C) Microsoft Corporation.  All rights reserved.
    > 	del main.obj
    > Microsoft (R) Program Maintenance Utility Version 14.23.28107.0
    > Copyright (C) Microsoft Corporation.  All rights reserved.
    > 	cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -O2 -MD -W0 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DNDEBUG -I. -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.7.25-winx64\include -IC:\Utils\postgresql\pgsql\include -I"C:\Program Files\MySQL\MySQL Server 8.0\include" -IC:\Qt\5.13.2\msvc2017_64\mkspecs\win32-msvc -Fo @C:\Users\John\AppData\Local\Temp\nm6458.tmp
    > main.cpp
    > 	link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:mysql.exe @C:\Users\John\AppData\Local\Temp\nm663D.tmp
    > main.obj : error LNK2019: unresolved external symbol _mysql_get_client_version@0 referenced in function _main
    > C:\Program Files\MySQL\MySQL Server 8.0\lib\libmysql.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
    > mysql.exe : fatal error LNK1120: 1 unresolved externals
    > NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX86\x86\link.EXE"' : return code '0x460'
    > Stop.
    

    It seems like a x86 version of the linker is being called within MSVC. Does that mean something is wrong with my environment variables?


  • Lifetime Qt Champion

    @JohnDog I'm not MSVC expert, but aren't there two versions of VC command prompts: one for x86 and one for x86_64?



  • @jsulm Thanks jsulm, that got it to recognize MySQL! I guess the default developer command prompt within Visual Studio is either the x86 or mixed environment. Just a note, I had to use 'x64 Native Tools Command Prompt for VS 2019' to get it to recognize, the cross tools one wouldn't recognize it.

    That solves this issue specifically, as I get the output needed.

    Thanks everyone for your help.


Log in to reply