Qt - 如何获取|编译Mysql驱动程序 [英] Qt - How to get|compile Mysql driver
问题描述
我想在Qt中创建一个依赖MySql的应用程序。一段时间后,我开始知道我的共享build没有MySql驱动程序(默认)。可以任何人说如何获取|编译它(共享和静态)。
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).
注意:我在Windows平台使用Qt-4.7.2
Note: I am using Qt-4.7.2 in Windows platform
编辑:
感谢vrince。这是他显示=>我做的方式。
Thanks to "vrince". This is the way he showed => I did.
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"
就是这样。您可以在
(Qt安装路径)\qt\plugins\sqldrivers
That's it. You can find the dlls in (Qt-installation path)\qt\plugins\sqldrivers
推荐答案
如果你计划重建Qt链接到MySQL,你现在可以停止,你不必! SQL驱动程序是插件(通过定义在运行时动态加载),可以独立编译。
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.
在Qt源代码树中查找驱动程序源如 qt / src / plugins / sqldrivers / mysql
然后构建它。这里的游戏是提供适当的MySQL开发标头和库(客户端),以便驱动程序将构建! (注意,如果你是一个窗口,它可能是32位版本的MySQL客户端,你需要即使你正在运行64位操作系统)。
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).
您可以通过 qmake
命令提供MySQL路径,参考Anton提供的文章,并更改 .pro
文件以匹配我的安装...如果需要,将更容易重建。
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.
编译成功,你将有一个很好的 qsqlmysql.dll
你必须复制到你用来运行你的应用程序的Qt目录,基本上像 qt / plugins / sqldrivers
在$ QT_DIR。
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.
这篇关于Qt - 如何获取|编译Mysql驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!