![](/img/trans.png)
[英]Qt C++ QMYSQL driver not loaded on MacOS - Tutorial for building QMYSQL Plugin
[英]Error Building MYSQL / QMYSQL Plugin on Windows with MariaDB
源代碼(帶下載鏈接):
MariaDB 5.5.56
https://downloads.mariadb.org/mariadb/5.5.56/
Qt 5.7.1
https://download.qt.io/official_releases/qt/5.7/5.7.1/single/
我在以下目錄中解壓並成功構建了 MariaDB 5.5.56:
D:\Source_Code-Third_Party\MariaDB\mariadb-5.5.56
Note: I "mkdir lib" and copy all ".lib"s into this folder post-build process.
然后我通過我編寫的批處理腳本使用以下命令:
set QMAKESPEC=win32-msvc2015
set _ROOT=
set VS2015PATH="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC"
pushd %VS2015PATH%
call vcvarsall.bat x64
popd
set CL=/MP
set INSTPREFIX=D:\Qt\5.7.1
set OPENSSL_PATH=%usefulStuff%
set OPENSSL_LIBS=%usefulStuff%\libs
set INCLUDE=%usefulStuff%\include;%INCLUDE%
set LIB=%usefulStuff%\lib;%LIB%
set LIBPATH=%usefulStuff%\lib;%LIBPATH%
cd qtbase
configure.bat -skip qtwebengine -skip qtpurchasing -skip qtlocation -skip qtconnectivity -mp -confirm-licence -nomake tests -nomake examples -debug-and-release -opensource -shared -dbus -mp -openssl -qtzlib -plugin-sql-mysql -I %usefulStuff%\include -L %usefulStuff%\lib -prefix %INSTPREFIX%
cd src\plugins\sqldrivers\mysql
set longDir=D:\Source_Code-Third_Party\qt-everywhere-opensource-src-5.7.1
REM (QMAKE COMMAND THAT CAUSES ERROR)
%longDir%\qtbase\bin\qmake "INCLUDEPATH+= D:/Source_Code-Third_Party/MariaDB/mariadb-5.5.56/include" "LIBS+=D:/Source_Code-Third_Party/MariaDB/mariadb-5.5.56/lib/libmysql.lib" mysql.pro
REM unsure if I should do an nmake here as well, or will the qtbase\nmake take care of everything (including plugin)
REM nmake
cd ..\..\..\..
nmake
nmake install
使用上述(QMAKE ERROR COMMAND),我得到錯誤:
Project ERRROR: No module claims plugin type 'sqldrivers'
當我將 (QMAKE ERROR COMMAND) 更改為以下內容時(使用不同的 qmake):
%longDir%\qtbase\qmake\qmake "INCLUDEPATH+= D:/Source_Code-Third_Party/MariaDB/mariadb-5.5.56/include" "LIBS+=D:/Source_Code-Third_Party/MariaDB/mariadb-5.5.56/lib/libmysql.lib" mysql.pro
我得到一個不同的錯誤:
Project ERROR: Cannot load qmodule.pri!
Error processing project file: mysql.pro
我能找到的一些參考資料:
https://forum.qt.io/topic/51808/notorious-qsqldatabase-qmysql-driver-not-loaded-but-available/4
以下鏈接(Qt 文檔)是代碼格式,因為“您需要至少 10 個聲望才能發布 2 個以上的鏈接。”
http://doc.qt.io/qt-5/sql-driver.html#qmysql-for-mysql-4-and-higher
本來可以用“qmysql”標記這個問題,但是“創建新標簽‘qmysql’至少需要 1500 個聲望。請嘗試從現有標簽列表中嘗試一些東西。”
---- 下面是相關的,但我更關心上面提到的錯誤----
我沒有使用 Qt 5.8.0 或 5.9.0,因為我無法使用“-skip”、“-plugin-sql-mysql”和/或“-qt-sql-mysql”來使用 configure.bat。 我收到如下錯誤:
"-qt-sql-mysql"
ERROR: Invalid value given for boolean command line option 'sql-mysql'.
OR
"-plugin-sql-mysql"
ERROR: Feature 'sql-mysql' was enabled, but the pre-condition 'libs.mysql' failed.
Check config.log for details.
OR
"-skip <somethingIShouldBeAbleToSkip>"
ERROR: Unknown command line option '-skip'.
我發現的 QTBUG 參考資料之一:
https://bugreports.qt.io/browse/QTBUG-58536
我按照以下說明在 Windows 上構建 MariaDB:
https://mariadb.com/kb/en/the-mariadb-library/Building_MariaDB_on_Windows/
構建后,您還應該繼續安裝到您的系統上。 此安裝過程將所有內容放入 QT 構建過程的正確文件夾結構中。
一旦你安裝了 MariaDB(它應該看起來就像一個 MySQL 安裝),你應該能夠遵循 MySQL 的標准 QT 構建說明。
http://doc.qt.io/qt-5/sql-driver.html
在配置 QT 時使用類似於“-qt-sql-mysql -IC:\\progra~1\\mysql\\include -LC:\\progra~1\\mysql\\lib”的東西。 我在 QT 5.7.1 中使用了這個過程。
除了來自 Snowman6286 的回答之外,使用默認 Qt 構建還必須執行以下操作:
Qt 構建時通常設置了 /MD 標志,因此必須以相同的方式構建 MariaDB,Qt 才能鏈接它。 有問題的行在 .\\cmake\\os\\Windows.cmake 中。 注釋掉讀取STRING(REPLACE "/MD" "/MT" "${flag}" "${${flag}}")
。 此外,不要通過注釋掉根 CMakeLists.txt 中讀取ADD_SUBDIRECTORY(win/upgrade_wizard)
的行來構建升級向導。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.