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

Cannot compile MySql driver under Windows



  • Hi,

    I need help with mysql driver compilation.

    I've downloaded Qt 5.13 for windows (x64).
    I've downloaded Mysql Connector and then i tried to compile drivers as describe here https://doc.qt.io/qt-5/sql-driver.html

    when running the command line :
    qmake.exe -- MYSQL_INCDIR=%MYSQLDIR%/include MYSQL_LIBDIR="%MYSQLDIR%/lib/opt"

    i got the following error :
    Project ERROR: Library 'mysql' is not defined.

    Somewhere i read that I must run qmake from the folder plugins\sqldrivers.
    When i do this i got the following result :

    C:\Qt\Qt5.13.2\5.13.2\Src\qtbase\src\plugins\sqldrivers>qmake.exe
    
    Running configuration tests...
    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 'C:\Qt\Qt5.13.2\5.13.2\msvc2015_64'.
    
    Prior to reconfiguration, make sure you remove any leftovers from
    the previous build.
    

    I see that mysql is not recognized. Anyone got an idea to put it to yes ?

    Thank you :)



  • Some news.

    Ive edited the mysql.pro file and comment the line :
    #QMAKE_USE += mysql

    then i change my script as follow :

    @echo off
    set QTDIR=C:\Qt\Qt5.13.2\5.13.2\msvc2015_64
    set MYSQCONNECTOR=C:\c++\extlibs-src\Mysql\x64
    set MYSQCONNECTORLIB=%MYSQCONNECTOR%\lib\vs14
    set MYSQCONNECTORINC=%MYSQCONNECTOR%\include
    set VCDIR=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC
    set PATH=%VCDIR%;%QTDIR%\bin;%PATH%
    
    @echo on
    cd %QTDIR%\..\Src\qtbase\src\plugins\sqldrivers\mysql
    qmake CONFIG+=x86_64 INCLUDEPATH+="%MYSQCONNECTORINC%" LIBS="%MYSQCONNECTORLIB%\mysqlclient.lib"
    nmake
    @echo off
    cd "c:\c++"
    

    The compilation seems to work well until the linking step. Now I got this error message :

    Qt5Sql.lib(Qt5Sql.dll) : fatal error LNK1112: type d'ordinateur module 'x64' en conflit avec le type d'ordinateur cible 'X86'
    

    It seems that the compiler is trying to make a x86 library with x64 ones. Now i want to force the compilation to be in x64.
    Anyone know how to do ?

    Thank you


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should activate the correct environment using Visual Studio's vcvars script.



  • Thank you for your answer.

    I tried to add this line to my batch file before calling qmake :
    call vcvarsall.bat x64

    And I still got the same error :/



  • I also tried to launch my script from the "Visual Studio command Prompt x64" and I still got the same error.

    do a sort of "make clean" before trying to recompile but I don't know how to do :/



  • Ok here is my new script executed from a x64 Visual studio command Prompt :

    @echo off
    set QTDIR=C:\Qt\Qt5.13.2\5.13.2\msvc2015_64
    set MYSQCONNECTOR=C:\c++\extlibs-src\Mysql\x64
    set MYSQCONNECTORLIB=%MYSQCONNECTOR%\lib\vs14
    set MYSQCONNECTORINC=%MYSQCONNECTOR%\include
    set PATH=%QTDIR%\bin;%PATH%
    
    @echo on
    cd %QTDIR%\..\Src\qtbase\src\plugins\sqldrivers\mysql
    qmake CONFIG+=x86_64 INCLUDEPATH+="%MYSQCONNECTORINC%" LIBS="%MYSQCONNECTORLIB%\mysqlclient.lib"
    nmake /f Makefile clean
    nmake
    

    And now I got a link error :

    mysqlclient.lib(my_init.obj) : error LNK2019: symbole externe non résolu __imp_RegCloseKey référencé dans la fonction win32_have_tcpip
    mysqlclient.lib(my_init.obj) : error LNK2019: symbole externe non résolu __imp_RegEnumValueA référencé dans la fonction win_init_registry
    mysqlclient.lib(my_init.obj) : error LNK2019: symbole externe non résolu __imp_RegOpenKeyExA référencé dans la fonction win32_have_tcpip
    mysqlclient.lib(common.obj) : error LNK2019: symbole externe non résolu __imp_EqualSid référencé dans la fonction "public: bool __cdecl Sid::operator==(class Sid const &)" (??8Sid@@QEAA_NAEBV0@@Z)
    mysqlclient.lib(common.obj) : error LNK2019: symbole externe non résolu __imp_GetTokenInformation référencé dans la fonction "public: __cdecl Sid::Sid(void *)" (??0Sid@@QEAA@PEAX@Z)
    mysqlclient.lib(common.obj) : error LNK2019: symbole externe non résolu __imp_IsValidSid référencé dans la fonction "public: __cdecl Sid::Sid(void *)" (??0Sid@@QEAA@PEAX@Z)
    mysqlclient.lib(common.obj) : error LNK2019: symbole externe non résolu __imp_LookupAccountNameW référencé dans la fonction "public: __cdecl Sid::Sid(wchar_t const *)" (??0Sid@@QEAA@PEB_W@Z)
    mysqlclient.lib(random.obj) : error LNK2019: symbole externe non résolu __imp_CryptAcquireContextA référencé dans la fonction "public: __cdecl TaoCrypt::OS_Seed::OS_Seed(void)" (??0OS_Seed@TaoCrypt@@QEAA@XZ)
    mysqlclient.lib(random.obj) : error LNK2019: symbole externe non résolu __imp_CryptReleaseContext référencé dans la fonction "public: __cdecl TaoCrypt::OS_Seed::~OS_Seed(void)" (??1OS_Seed@TaoCrypt@@QEAA@XZ)
    mysqlclient.lib(random.obj) : error LNK2019: symbole externe non résolu __imp_CryptGenRandom référencé dans la fonction "public: __cdecl TaoCrypt::RandomNumberGenerator::RandomNumberGenerator(void)" (??0RandomNumberGenerator@TaoCrypt@@QEAA@XZ)
    

    Maybe ond day it will work :/



  • Ok my bad. I was linking the mad library (the static version) instead of the shared version :) now it's work :) thank you



  • @SGaist
    qt with mysql build is a very bad experience .
    Many peoples can't get success on build qt with mysql ,but there is no a instruction step by step long time.



  • @Higestromm
    Cloud you share which link for download Mysql Connector c++?
    When build a static qt with mysql , the Mysql Connector c++ is a big problem .
    Seems mysqlclient.lib is complied by MinGW,if use build a static qt by VS and include mysqlclient.lib(build by MinGW) will get failure.
    Did you try build a static with mysql by VS?


Log in to reply