How to create Qt 6.5 mysql driver with cmake?
-
@Saad02 Are you serious with the last screenshot? I mean -
<qt_installation_path>
should be replaced with your ... qt installation path. Also the command line properly tells you that qt-cmake is not found so what do you expect?? -
@Christian-Ehrlicher Sir, it finds qt-make properly. And I have never made any driver or binary on by own. Then should I remove <qt_installation_path> and retry?
-
@Saad02 Ok, I understood little.
Code:
qt-cmake -G Ninja C:/Qt/6.5.1/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=C:/Qt/<platform> -DMySQL_INCLUDE_DIR="C:/mysql-8.0.33-winx64/include" -DMySQL_LIBRARY="C:/mysql-8.0.33-winx64/lib/mysqlclient.<so|dylib>"Do I need to change anything here now?
-
@Saad02 try the following batch script (adjust the paths if necessary first):
set PATH=%PATH%;C:\Qt\Tools\mingw1120_64\bin;C:\Qt\Tools\CMake_64\bin cd C:\Qt\6.5.1\Src\qtbase\src\plugins\sqldrivers call C:\Qt\6.5.1\mingw_64\bin\qt-cmake.bat -G "MinGW Makefiles" . -DMySQL_INCLUDE_DIR="C:\mysql-8.0.33-winx64\include" -DMySQL_LIBRARY="C:\mysql-8.0.33-winx64\lib\libmysql.lib" -DCMAKE_INSTALL_PREFIX="C:\Qt\6.5.1\mingw_64" -DCMAKE_C_COMPILER="gcc.exe" -DCMAKE_CXX_COMPILER="g++.exe" mingw32-make mingw32-make install pause
-
@thecodemonkey I got some error when I used the command mingw32-make.
![519252e7-a5af-4757-a934-d49f3834d0c0-image.png](Request Entity Too Large) -
@thecodemonkey Sorry, the image is too large. I think I should just copy paste it.
Error:
C:\Qt\6.5.1\Src\qtbase\src\plugins\sqldrivers>mingw32-make
[ 4%] Built target QMYSQLDriverPlugin_version_script
[ 8%] Automatic MOC for target QMYSQLDriverPlugin
[ 8%] Built target QMYSQLDriverPlugin_autogen
[ 32%] Built target QMYSQLDriverPlugin
[ 36%] Built target QODBCDriverPlugin_version_script
[ 40%] Automatic MOC for target QODBCDriverPluginAutoMoc subprocess error
The moc process failed to compile
"SRC:/odbc/qsql_odbc_p.h"
into
"SRC:/odbc/QODBCDriverPlugin_autogen/include/moc_qsql_odbc_p.cpp"
included by
"SRC:/odbc/qsql_odbc.cpp"Command
C:/Qt/6.5.1/mingw_64/./bin/moc.exe -DMINGW_HAS_SECURE_API=1 -DQODBCDriverPlugin_EXPORTS -DQT_CORE_LIB -DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPRECATED_UP_TO=0x040800 -DQT_EXPLICIT_QFILE_CONSTRUCTION_FROM_PATH -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_DEBUG -DQT_NO_EXCEPTIONS -DQT_NO_JAVA_STYLE_ITERATORS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_PLUGIN -DQT_SQL_LIB -DQT_WARN_DEPRECATED_UP_TO=0x070000 -DUNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_UNICODE -D_WIN64 -IC:/Qt/6.5.1/Src/qtbase/src/plugins/sqldrivers/odbc -IC:/Qt/6.5.1/Src/qtbase/src/plugins/sqldrivers/include -IC:/MinGW/include -IC:/Qt/6.5.1/mingw_64/include/QtCore -IC:/Qt/6.5.1/mingw_64/include -IC:/Qt/6.5.1/mingw_64/mkspecs/win32-g++ -IC:/Qt/6.5.1/mingw_64/include/QtCore/6.5.1 -IC:/Qt/6.5.1/mingw_64/include/QtCore/6.5.1/QtCore -IC:/Qt/6.5.1/mingw_64/include/QtSql/6.5.1 -IC:/Qt/6.5.1/mingw_64/include/QtSql/6.5.1/QtSql -IC:/Qt/6.5.1/mingw_64/include/QtSql -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++ -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/x86_64-w64-mingw32 -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/backward -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include-fixed -IC:/Qt/Tools/mingw1120_64/x86_64-w64-mingw32/include --include C:/Qt/6.5.1/Src/qtbase/src/plugins/sqldrivers/odbc/QODBCDriverPlugin_autogen/moc_predefs.h --output-dep-file -o C:/Qt/6.5.1/Src/qtbase/src/plugins/sqldrivers/odbc/QODBCDriverPlugin_autogen/include/moc_qsql_odbc_p.cpp C:/Qt/6.5.1/Src/qtbase/src/plugins/sqldrivers/odbc/qsql_odbc_p.h
Output
:/Qt/6.5.1/mingw_64/include/QtCore/qnamespace.:24:1: error: Parse error at "attribute"
AutoMoc subprocess error
The moc process failed to compile
"SRC:/odbc/main.cpp"
into
"SRC:/odbc/QODBCDriverPlugin_autogen/include/main.moc"
included by
"SRC:/odbc/main.cpp"Command
C:/Qt/6.5.1/mingw_64/./bin/moc.exe -DMINGW_HAS_SECURE_API=1 -DQODBCDriverPlugin_EXPORTS -DQT_CORE_LIB -DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPRECATED_UP_TO=0x040800 -DQT_EXPLICIT_QFILE_CONSTRUCTION_FROM_PATH -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_DEBUG -DQT_NO_EXCEPTIONS -DQT_NO_JAVA_STYLE_ITERATORS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_PLUGIN -DQT_SQL_LIB -DQT_WARN_DEPRECATED_UP_TO=0x070000 -DUNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_UNICODE -D_WIN64 -IC:/Qt/6.5.1/Src/qtbase/src/plugins/sqldrivers/odbc -IC:/Qt/6.5.1/Src/qtbase/src/plugins/sqldrivers/include -IC:/MinGW/include -IC:/Qt/6.5.1/mingw_64/include/QtCore -IC:/Qt/6.5.1/mingw_64/include -IC:/Qt/6.5.1/mingw_64/mkspecs/win32-g++ -IC:/Qt/6.5.1/mingw_64/include/QtCore/6.5.1 -IC:/Qt/6.5.1/mingw_64/include/QtCore/6.5.1/QtCore -IC:/Qt/6.5.1/mingw_64/include/QtSql/6.5.1 -IC:/Qt/6.5.1/mingw_64/include/QtSql/6.5.1/QtSql -IC:/Qt/6.5.1/mingw_64/include/QtSql -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++ -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/x86_64-w64-mingw32 -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/backward -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include-fixed -IC:/Qt/Tools/mingw1120_64/x86_64-w64-mingw32/include --include C:/Qt/6.5.1/Src/qtbase/src/plugins/sqldrivers/odbc/QODBCDriverPlugin_autogen/moc_predefs.h --output-dep-file -o C:/Qt/6.5.1/Src/qtbase/src/plugins/sqldrivers/odbc/QODBCDriverPlugin_autogen/include/main.moc C:/Qt/6.5.1/Src/qtbase/src/plugins/sqldrivers/odbc/main.cpp
Output
:/Qt/6.5.1/mingw_64/include/QtCore/qnamespace.:24:1: error: Parse error at "attribute"
mingw32-make[2]: *** [odbc\CMakeFiles\QODBCDriverPlugin_autogen.dir\build.make:70: odbc/CMakeFiles/QODBCDriverPlugin_autogen] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:355: odbc/CMakeFiles/QODBCDriverPlugin_autogen.dir/all] Error 2
mingw32-make: *** [Makefile:145: all] Error 2 -
@Saad02 I know, building SQL drivers can be a pain in the A-S-S. That's the reason I provide pre-built QMYSQL drivers on my github page, to spare others that pain
Does anything change if you run configure.bat first?
set PATH=%PATH%;C:\Qt\Tools\mingw1120_64\bin;C:\Qt\Tools\CMake_64\bin cd C:\Qt\6.5.1\Src configure.bat -sql-mysql -- -DCMAKE_INCLUDE_PATH="C:\mysql-8.0.33-winx64\include" -DCMAKE_LIBRARY_PATH="C:\mysql-8.0.33-winx64\lib" cd C:\Qt\6.5.1\Src\qtbase\src\plugins\sqldrivers call C:\Qt\6.5.1\mingw_64\bin\qt-cmake.bat -G "MinGW Makefiles" . -DMySQL_INCLUDE_DIR="C:\mysql-8.0.33-winx64\include" -DMySQL_LIBRARY="C:\mysql-8.0.33-winx64\lib\libmysql.lib" -DCMAKE_INSTALL_PREFIX="C:\Qt\6.5.1\mingw_64" -DCMAKE_C_COMPILER="gcc.exe" -DCMAKE_CXX_COMPILER="g++.exe" mingw32-make mingw32-make install pause
-
@Saad02 said in How to create Qt 6.5 mysql driver with cmake?:
@Saad02 Ok, I understood little.
Code:
qt-cmake -G Ninja C:/Qt/6.5.1/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=C:/Qt/<platform> -DMySQL_INCLUDE_DIR="C:/mysql-8.0.33-winx64/include" -DMySQL_LIBRARY="C:/mysql-8.0.33-winx64/lib/mysqlclient.<so|dylib>"Do I need to change anything here now?
As already said several times: all the values between a < and > must be replaced by suitable values.
-
@thecodemonkey Sir, I extracted those in my project file is it, ok? (But it didn't work)
And did you mean any of the folder in Qt by "subdirectory "?Also, this code also got me the same error.
-
-
@Saad02 there are two possibilites, both should work:
- in Qt installation dir. For MinGW that would be something like C:\Qt\6.5.1\mingw_64\plugins\sqldrivers
- a subdirectory in your project build path (where the compiler creates the exe file of your project), like this:
libmysql.dll must be accessible, too. So either copy it to your project build path, or some other path that is added to your PATH environment variable
-
@thecodemonkey Sir, copied all files in release and debug, qmysql.lib in C:\Qt\6.5.1\mingw_64\plugins\sqldrivers and also added the folder in environment. But it didn't work.
-
@Saad02 said in How to create Qt 6.5 mysql driver with cmake?:
But it didn't work.
Please be more specific
-
Also, added "qsqlmysql.dll_Qt_SQL_driver_6.5.1_MinGW_11.2.0_64-bit" folder in environment variables' system variables' path.
I have nothing to hide :) -
@thecodemonkey Sir, I am providing you the qt creator messages.
Application Output:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMARIADB QMYSQL QODBC QPSQLCompile Output:
C:/Qt/Tools/mingw1120_64/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'C:/Users/Saad/Documents/qt c++/build-database-Desktop_Qt_6_5_1_MinGW_64_bit-Release'
C:\Qt\6.5.1\mingw_64\bin\uic.exe ..\database\mainwindow.ui -o ui_mainwindow.h
g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../database -I. -IC:/Qt/6.5.1/mingw_64/include -IC:/Qt/6.5.1/mingw_64/include/QtWidgets -IC:/Qt/6.5.1/mingw_64/include/QtGui -IC:/Qt/6.5.1/mingw_64/include/QtSql -IC:/Qt/6.5.1/mingw_64/include/QtCore -Irelease -I. -I/include -IC:/Qt/6.5.1/mingw_64/mkspecs/win32-g++ -o release\main.o ..\database\main.cpp
g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../database -I. -IC:/Qt/6.5.1/mingw_64/include -IC:/Qt/6.5.1/mingw_64/include/QtWidgets -IC:/Qt/6.5.1/mingw_64/include/QtGui -IC:/Qt/6.5.1/mingw_64/include/QtSql -IC:/Qt/6.5.1/mingw_64/include/QtCore -Irelease -I. -I/include -IC:/Qt/6.5.1/mingw_64/mkspecs/win32-g++ -o release\mainwindow.o ..\database\mainwindow.cpp
C:\Qt\6.5.1\mingw_64\bin\moc.exe -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN --include "C:/Users/Saad/Documents/qt c++/build-database-Desktop_Qt_6_5_1_MinGW_64_bit-Release/release/moc_predefs.h" -IC:/Qt/6.5.1/mingw_64/mkspecs/win32-g++ -I"C:/Users/Saad/Documents/qt c++/database" -IC:/Qt/6.5.1/mingw_64/include -IC:/Qt/6.5.1/mingw_64/include/QtWidgets -IC:/Qt/6.5.1/mingw_64/include/QtGui -IC:/Qt/6.5.1/mingw_64/include/QtSql -IC:/Qt/6.5.1/mingw_64/include/QtCore -I. -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++ -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/x86_64-w64-mingw32 -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/backward -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include-fixed -IC:/Qt/Tools/mingw1120_64/x86_64-w64-mingw32/include ..\database\mainwindow.h -o release\moc_mainwindow.cpp
g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../database -I. -IC:/Qt/6.5.1/mingw_64/include -IC:/Qt/6.5.1/mingw_64/include/QtWidgets -IC:/Qt/6.5.1/mingw_64/include/QtGui -IC:/Qt/6.5.1/mingw_64/include/QtSql -IC:/Qt/6.5.1/mingw_64/include/QtCore -Irelease -I. -I/include -IC:/Qt/6.5.1/mingw_64/mkspecs/win32-g++ -o release\moc_mainwindow.o release\moc_mainwindow.cpp
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\database.exe release/main.o release/mainwindow.o release/moc_mainwindow.o C:\Qt\6.5.1\mingw_64\lib\libQt6Widgets.a C:\Qt\6.5.1\mingw_64\lib\libQt6Gui.a C:\Qt\6.5.1\mingw_64\lib\libQt6Sql.a C:\Qt\6.5.1\mingw_64\lib\libQt6Core.a -lmingw32 C:\Qt\6.5.1\mingw_64\lib\libQt6EntryPoint.a -lshell32
mingw32-make[1]: Leaving directory 'C:/Users/Saad/Documents/qt c++/build-database-Desktop_Qt_6_5_1_MinGW_64_bit-Release'
17:03:21: The process "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" exited normally.
17:03:21: Elapsed time: 00:16. -
@thecodemonkey Nothing changed. I got the same output. Do I have to somewhere else except Qt Creator?