Build the MySQL driver in QT 5.11



  • hello all can someone help me please
    Sorry for my english

    I can not compile the driver for MySql, read a lot of information

    First I compiled qt 5.11 from the sources with the keys
    -shared -debug-and-release -platform win32-g++ -prefix D:\Qt\5.11\5.11-x64 -opensource -confirm-license -c++std c++14 -nomake examples -skip wayland -skip purchasing -skip serialbus -skip qtserialport -skip script -skip scxml -skip speech -skip location -opengl desktop -qt-zlib -qt-pcre -qt-libpng -qt-freetype -openssl-linked -I D:\Qt\openssl-1.0.2\dist\include -L D:\Qt\openssl-1.0.2\dist\lib OPENSSL_LIBS="-llibssl -llibcrypto -luser32 -lgdi32 -lwsock32 -lws2_32"

    Compiled on Windows 10 Pro x64. To compile, I used mingw-w64, also installed everything needed to build.

    Downloaded and installed "MySQL Connector C 6.1", installed it into the C: \ MySql directory. (first installed the version of x64, but then after it did not work with it reinstalled on x86 and did all the work with it)

    Then, as it is written in the official documentation http://doc.qt.io/qt-5/sql-driver.html#qmysql moved to the directory "%QTDIR%\qtbase\src\plugins\sqldrivers" and executed there
    "qmake -- MYSQL_INCDIR=C:/MySQL/include "MYSQL_LIBDIR=C:/MYSQL/lib" "
    mingw32-make sub-mysql

    but got an error
    "mingw32-make: *** No rule to make target 'sub-mysql'. Stop."

    Looked at the Makefile, sub-mysql does not really exist there, if just do mingw32-make then the assembly of OBDC and SqlLite is going on, Mysql is not going to.

    After that, I read a lot of information and found this resource https://mike-mvk.livejournal.com/4196.html in which they say that first need to convert libmysql.dll to libmysql.a, performed the transformation and repeated everything anew, the error is the same.
    Then I tried to do as written on the specified resource
    cd %QTDIR%\src\plugins\sqldrivers\mysql
    qmake -o Makefile "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MySQL\lib\libmysql.a" mysql.pro

    but again got an error
    Project ERROR: Library 'mysql' is not defined.

    After that I decided to build QT already with MySql support, took clean sources and tried to configure with parameters
    -shared -debug-and-release -platform win32-g++ -prefix D:\Qt\5.11\5.11-x64 -opensource -confirm-license -c++std c++14 -nomake examples -skip wayland -skip purchasing -skip serialbus -skip qtserialport -skip script -skip scxml -skip speech -skip location -opengl desktop -qt-zlib -qt-pcre -qt-libpng -no-libjpeg -qt-freetype -openssl-linked -I D:\Qt\openssl-1.0.2\dist\include -L D:\Qt\openssl-1.0.2\dist\lib OPENSSL_LIBS="-llibssl -llibcrypto -luser32 -lgdi32 -lwsock32 -lws2_32" -sql-mysql MYSQL_INCDIR=C:\MySQL\include MYSQL_LIBDIR=C:\MySQL\lib MYSQL_LIBS=-lmysqld

    But when configuring, MySql does not pass "MySql .. no" and at the end there is an error message "ERROR: Feature 'sql-mysql' was enabled, but the pre-condition 'libs.mysql' failed."

    I decided to download qt-opensource-windows-x86-5.11.1.exe and compile the x86 version of the driver, because somewhere I read that it will work with x64, but got all the same errors.

    Has anyone successfully assembled the MySql driver for Qt 5.11 or 5.10?
    If you compiled, then tell me please, where there can be a mistake, re-read the entire Internet, none of the methods helped solve the problem.



  • Hi @vovan1982

    Welcome!

    I have written about the need NOT to build Qt for x64 in the past. Msys2 has wonderful 64bit system already done. They currently target Qt5.11.1 and QtCreator 4.6.2. Even though our company licenses Qt, I use Msys2 to develop and we use SQL throughout.

    Another advantage you get is that you are using the most up-to-date GCC/G++/GDB/CLANG available.

    I, personally, never want to build the tools I use. I just want to have all the FUN! :D



  • Hi @Buckwheat

    Prompt please, there is an instruction how to build Mysql the driver in MSYS2?



  • Hi @vovan1982 ,

    The qsqlmysql.dll and qsqlmysqld.dll for the QMYSQL driver are already built. No need to build them.



  • @vovan1982 ,

    One more thing... That is why I choose to use MSys2. Because I get both 32 and 64 bit complete builds with the most recent GNU toolchain.



  • hi @Buckwheat
    can you tell me how i find the plugins already built despite the qt tutorial tell me to build it.....i spend a lot of time on it?



  • @mohamed-Qt said in Build the MySQL driver in QT 5.11:

    d the plugins already built despite the qt tutorial tell me to build it.....i spend a lot of time on it?

    OK, first, I don't know why it would say in the tutorial that you need to build anthing from Qt with MSys2! Simply install it using 'pacman!'

    In any case, from within your msys2 shell.

    cd /mingw[32|64]/share/qt5/plugins/sqldrivers

    Make sure when you are building you have QT += SQL in your PRO file.
    Make sure you also have the DLLs for MySQL available. SQLite is built in. I beleive QT5.11.1 for MSys2 says SQLite v3.24 currently.

    So anyone reading this knows... I have NEVER had to build anything for 64bit or 32bit with MSys2. I use it for developing commercial applications (I have purchased commercial license but prefer to develop using the OpenSource so I can use more recent gcc/g++). The only caveat is... You cannot use the new WebKit because Chromium engine only builds with M$ and not any MingW. MSys2 makes available the older WebKit and it works just fine for the small things I use it for in my application.

    For basic installation after you install the GNU toolchain:
    pacman -Syu mingw-w64-i686-qt5 ---> for 32-bit
    pacman -Syu mingw-w64-x86_64-qt5 ---> for 64-bit
    pacman -Syu mingw-w64-i686-qtwebkit ---> for 32-bit
    pacman -Syu mingw-w64-x86_64-qtwebkit ---> for 64-bit

    For my qtcreator usage:
    pacman -Syu mingw-w64-x86_64-qt-creator --> Version 4.6.2

    I never install static libraries because I use lots of plugins to keep a small footprint for my application. I also have no issues moving to *nix because of the GNU toolchain.

    The idea is to enjoy developing not spending half my time building "because I can." Enjoy Qt! Create great and wonderful Apps! Set market trends! That's why we write software!



  • Solved the problem

    I will describe what I had a problem with.

    I was advised to use the "native driver QT" for mysql. Taking the native driver tried to use it with the QT that I collected, but I got "Driver not loaded". In principle, it is expected. The driver is compiled for x86, and I compiled QT for x64. Then I tried to connect to mysql using the standard set of QT, mingw and native driver, the connection was successful, which in principle is also expected. But the fact that the driver for x86 refused to work with my assembly and when assembling the driver in the log was an error

    D:\Qt\5.11.1\config.tests\mysql/main.cpp:10: undefined reference to `mysql_get_client_version'
    collect2.exe: error: ld returned 1 exit status
    mingw32-make: *** [Makefile:64: mysql.exe] Error 1

    obviously, indicates that the problem is most likely in the mysql library, which I provide with my compiled qt.

    And then I remembered that at the beginning when I was trying to build a driver with "MySQL Connector C 6.1 x64" I did not convert libmysql.dll to libmysql.a.
    Removing "MySQL Connector C 6.1 x86" I put "MySQL Connector C 6.1 x64" converted libmysql.dll to libmysql.a and started configuring clean source with the following keys:

    -shared -debug-and-release -platform win32-g++ -prefix D:\Qt\5.11.1\5.11.1-x64 -opensource -confirm-license -c++std c++14 -nomake examples -skip wayland -skip purchasing -skip serialbus -skip qtserialport -skip script -skip scxml -skip speech -skip location -opengl desktop -qt-zlib -qt-pcre -qt-libpng -no-libjpeg -qt-freetype -openssl-linked -I D:\Qt\openssl-1.0.2\dist\include -L D:\Qt\openssl-1.0.2\dist\lib OPENSSL_LIBS="-llibssl -llibcrypto -luser32 -lgdi32 -lwsock32 -lws2_32" -sql-mysql MYSQL_INCDIR=C:\MySQL64\include MYSQL_LIBDIR=C:\MySQL64\lib MYSQL_LIBS="-lmysql"

    As a result, the MySql check during configuration was successful "MySql .. yes" and after building appeared the driver for mysql. Putting the driver in the folder Qt Creator and the file libmysql.dll in the project folder, all worked.

    The topic can be closed.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.