找了很多编译博文,都错误。最后找到了正确编译办法:
https://zhuanlan.zhihu.com/p/567883165
- 直接下载编译好的源码及dll文件
https://download.csdn.net/download/quantum7/89760587
- 安装VS Virsual Studio 2022 Community
D:\Program Files\Microsoft Visual Studio\2022\Community
要有VC++/cmake等。
- 安装MySQL
C:\Program Files\MySQL\MySQL Server 8.0
- 安装QT
D:\Qt
要选中三项:
MSVC_2019 64-bit
MinGW 11.2.0 64 bit
Sources
- 配置路径
根据自己的安装来设置,也可以设置到系统路径中。
set PATH=%PATH%;D:\Qt\Tools\CMake_64\bin;D:\Qt\Tools\Ninja
- 来到sql驱动源码目录
D:\Qt\6.7.2\Src\qtbase\src\plugins\sqldrivers
- 命令1
D:\Qt\6.7.2\Src\qtbase\src\plugins\sqldrivers>call "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.11.2
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
D:\Qt\6.7.2\Src\qtbase\src\plugins\sqldrivers\mysql> cd ..
D:\Qt\6.7.2\Src\qtbase\src\plugins\sqldrivers>call "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.11.2
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
- 命令2
D:\Qt\6.7.2\Src\qtbase\src\plugins\sqldrivers>call D:\Qt\6.7.2\msvc2019_64\bin\qt-cmake.bat -G "Ninja" . -DMySQL_INCLUDE_DIR="c:\Program Files\MySQL\MySQL Server 8.0\include" -DMySQL_LIBRARY="c:\Program Files\MySQL\MySQL Server 8.0\lib\libmysql.lib" -DCMAKE_INSTALL_PREFIX="d:\QtTemp\msvc2019_64" -DCMAKE_BUILD_TYPE=Release
-- The CXX compiler identification is MSVC 19.41.34120.0
-- The C compiler identification is MSVC 19.41.34120.0
-- The ASM compiler identification is MSVC
-- Found assembler: D:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
-- Performing Test HAVE_STDATOMIC
-- Performing Test HAVE_STDATOMIC - Success
-- Found WrapAtomic: TRUE
-- CMAKE_BUILD_TYPE was already explicitly set to: 'Release'
CMake Error at CMakeLists.txt:52 (add_subdirectory):
The source directory
D:/Qt/6.7.2/Src/qtbase/src/plugins/sqldrivers/mysql
does not contain a CMakeLists.txt file.
-- Configuration summary shown below. It has also been written to D:/Qt/6.7.2/Src/qtbase/src/plugins/sqldrivers/config.summary
-- Configure with --log-level=STATUS or higher to increase CMake's message verbosity. The log level does not persist across reconfigurations.
-- Configure summary:
Qt Sql Drivers:
DB2 (IBM) .............................. no
InterBase .............................. no
MySql .................................. yes
OCI (Oracle) ........................... no
ODBC ................................... yes
PostgreSQL ............................. no
SQLite ................................. yes
Using system provided SQLite ......... no
Mimer .................................. no
-- Configuring incomplete, errors occurred!
- 命令3
D:\Qt\6.7.2\Src\qtbase\src\plugins\sqldrivers>ninja
[23/23] Linking CXX shared module plugins\sqldrivers\qsqlite.dll
- 命令4
D:\Qt\6.7.2\Src\qtbase\src\plugins\sqldrivers>ninja install
[0/1] Install the project...-- Install configuration: "Release"
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginConfig.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginConfigVersion.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginConfigVersionImpl.cmake
-- Installing: D:/QtTemp/msvc2019_64/./plugins/sqldrivers/qsqlmysql.dll
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginTargets.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginTargets-release.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginAdditionalTargetInfo.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QODBCDriverPluginConfig.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QODBCDriverPluginConfigVersion.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QODBCDriverPluginConfigVersionImpl.cmake
-- Installing: D:/QtTemp/msvc2019_64/./plugins/sqldrivers/qsqlodbc.dll
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QODBCDriverPluginTargets.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QODBCDriverPluginTargets-release.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QODBCDriverPluginAdditionalTargetInfo.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QSQLiteDriverPluginConfig.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QSQLiteDriverPluginConfigVersion.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QSQLiteDriverPluginConfigVersionImpl.cmake
-- Installing: D:/QtTemp/msvc2019_64/./plugins/sqldrivers/qsqlite.dll
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QSQLiteDriverPluginTargets.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QSQLiteDriverPluginTargets-release.cmake
-- Installing: D:/QtTemp/msvc2019_64/lib/cmake/Qt6Sql/Qt6QSQLiteDriverPluginAdditionalTargetInfo.cmake
- 检查文件产生
- 复制到
D:\Qt\6.7.2\mingw_64\plugins\sqldrivers