windows Qt - 如何获取|编译Mysql驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6483523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Qt - How to get|compile Mysql driver
提问by prabhakaran
I am trying to make a MySql-dependent app in Qt. After some time I came to know that my shared-build is not having MySql driver(by default). Can Anybody say how to get|compile it (both in shared and static).
我正在尝试在 Qt 中制作一个依赖于 MySql 的应用程序。一段时间后,我才知道我的共享构建没有 MySql 驱动程序(默认情况下)。任何人都可以说如何获取|编译它(共享和静态)。
Note: I am using Qt-4.7.2 in Windows platform
注意:我在 Windows 平台上使用 Qt-4.7.2
EDIT:Thanks to "vrince". This is the way he showed => I did.
编辑:感谢“vrince”。这就是他展示的方式 => 我做到了。
1)Open qt-command prompt
2)Goto (Qt's installation path)\qt\src\plugins\sqldrivers\mysql
in my case:
D:\TempInstallationFolder\Qt\dynamic-New\qt\src\plugins\sqldrivers\mysql
3)qmake
4)make
or
mingw32-make (provided your PATH variable contains "(Qt installation path)\mingw\bin")
("make" should work if you didn't mess up with path variables. It in turn
invokes mingw32-make. I messed up this a little bit. So I invoked
mingw32-make directly.)
5)In the above command you have to indicate the mysql's "lib" path,
and "include" path through the compile flag options. Or Add those lines
in the pro file like below
INCLUDEPATH += "C:\Program Files\MySQL\MySQL Server 5.1\include"
LIBS += -L"C:\Program Files\MySQL\MySQL Server 5.1\lib\opt"
That's it. You can find the dlls in (Qt-installation path)\qt\plugins\sqldrivers
就是这样。您可以在(Qt-安装路径)\qt\plugins\sqldrivers 中找到这些dll
回答by vrince
If you plan to rebuild Qt linked to MySQL you can stop now you don't have to ! SQL drivers are plugins (by definition dynamically loaded at run time) and can be compiled independently.
如果您计划重建链接到 MySQL 的 Qt,您现在可以停止,您不必这样做!SQL 驱动程序是插件(根据定义在运行时动态加载)并且可以独立编译。
Find the driver sources in the Qt source tree somthing like qt/src/plugins/sqldrivers/mysql
then build it. The game here is to provide the proper MySQL development headers and libraries (client ones) so that the driver will build ! (Be aware if you are one windows it may be 32bits version of MySQL client you need even if you are running a 64bits OS).
在 Qt 源代码树中找到驱动程序源代码,qt/src/plugins/sqldrivers/mysql
然后构建它。这里的游戏是提供正确的 MySQL 开发头文件和库(客户端的),以便驱动程序构建!(请注意,如果您是一个 Windows,即使您运行的是 64 位操作系统,它也可能是您需要的 32 位版本的 MySQL 客户端)。
You can provide MySQL path via the qmake
command for that refer to the article given by Anton, personally I copy and change the .pro
file to match my installation ... easier to rebuild later if needed.
您可以通过qmake
命令提供 MySQL 路径,请参阅 Anton 给出的文章,我个人复制并更改.pro
文件以匹配我的安装......如果需要,以后更容易重建。
Once the build succeeded, you will have a nice qsqlmysql.dll
you must copy into the Qt dir you use to run you apps basically something like qt/plugins/sqldrivers
in the $QT_DIR.
一旦构建成功,你将有一个很好的qsqlmysql.dll
你必须复制到你用来运行你的应用程序的 Qt 目录中,基本上类似于qt/plugins/sqldrivers
$QT_DIR 中的内容。
回答by Kiran Thilak
Building for QT5.13 using MinGW32 1. Download MySql C Connector v6.1.
使用 MinGW32 构建 QT5.13 1. 下载 MySql C 连接器 v6.1。
> Download the MySql Installer from:
> <https://dev.mysql.com/downloads/installer/>
> Install C Connector 6.1 (Note the location we will need it later)
2. Getting QT Source Ready
2. 准备好 QT 源代码
> To build a plugin for QT u need to get its source. You can install it from Maintenance Tool or manually get it from github repository.
Building Plugin
Open MinGW CMD (Windows -> Start Menu -> Programs -> Qt 5.13.1 -> 5.13.1-> MinGW 7.3.0 (32-bit) -> Qt 5.13.1 (MinGW 7.3.0 32-bit) )
cd to sqldrivers path in qt source
cd D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers
Run qmake here.
qmake sqldrivers.pro
(to create qtsqldrivers-config.pri )cd to mysql.
cd D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers\mysql
- Run qmake here. qmake mysql.pro
Add the plugin to the list
Once successfully build you will find qsqlmysql.dll and qsqlmysqld.dll in the following location
D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers
Copy both qsqlmysql.dll and qsqlmysqld.dll and place them in the compiler's plugin directory
D:\QT\Qt5.13.1\5.13.1\mingw73_32\plugins\sqldrivers
构建插件
打开 MinGW CMD (Windows -> 开始菜单 -> 程序 -> Qt 5.13.1 -> 5.13.1-> MinGW 7.3.0 (32-bit) -> Qt 5.13.1 (MinGW 7.3.0 32-bit) )
cd 到 qt 源中的 sqldrivers 路径
cd D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers
在这里运行 qmake。
qmake sqldrivers.pro
(创建 qtsqldrivers-config.pri )cd 到 mysql。
cd D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers\mysql
- 在这里运行 qmake。qmake mysql.pro
将插件添加到列表中
成功构建后,您将在以下位置找到 qsqlmysql.dll 和 qsqlmysqld.dll
D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers
复制 qsqlmysql.dll 和 qsqlmysqld.dll 并将它们放在编译器的插件目录中
D:\QT\Qt5.13.1\5.13.1\mingw73_32\plugins\sqldrivers
Error in Building?
构建错误?
Library 'mysql' is not defined.
In file cd
D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers\mysql\mysql.pro
Commend the line
QMAKE_USE += mysql
Adding Library path and Include path.
Add the following to mysql.pro at end
LIBS += -L'C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/lib/' -llibmysql INCLUDEPATH += 'C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/include' DEPENDPATH += 'C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/include'
QSqlDatabase: QMYSQL driver not loaded
Add the .dll files from C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/lib to D:\QT\Qt5.13.1\5.13.1\mingw73_32\bin
未定义库“mysql”。
在文件 cd
D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers\mysql\mysql.pro
表扬一下
QMAKE_USE += mysql
添加库路径和包含路径。
将以下内容添加到 mysql.pro 最后
LIBS += -L'C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/lib/' -llibmysql INCLUDEPATH += 'C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/include' DEPENDPATH += 'C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/include'
QSqlDatabase:未加载 QMYSQL 驱动程序
将 C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/lib 中的 .dll 文件添加到 D:\QT\Qt5.13.1\5.13.1\mingw73_32\bin