Compile the MySQL driver of QT in Windows
Compile the MySQL driver of QT in Windows
1. Download MySQL
URL http://dev.mysql.com/downloads/mysql/, select windows (x86, 32-bit), ZIP Archive corresponding download. Note that you need to download the full version, which is larger than MB. Because the library provided by the installer is incomplete, a lot of "undefined reference" will appear when you use it directly ".
2. Install MySQL
Decompress the downloaded package to the installation path. Note that the QT compiling environment does not support spaces. ensure that there are no spaces in the installation path. (The installation path in this article is D: \ Development \ mysql)
3. Compile qsqlmysql
Method 1: Change mysql. Pro
(1) go to the source code directory of qsqlmysql, and SRC \ plugins \ sqldrivers \ mysql under the QT installation directory.
(2) Compile
Add includepath + = D: \ Development \ mysql \ include and libs + = D: \ Development \ mysql \ Lib \ libmysql. Lib. The added mysql. Pro file is as follows:
Target = qsqlmysql
Sources = Main. cpp
Export depath + = D:/development/MySQL/include
Libs + = D:/development/MySQL/lib/libmysql. Lib
Include (.../../SQL/Drivers/MySQL/qsql_mysql.pri)
Include (../qsqldriverbase. PRI)
Then, you can use qtcreator to open the project file and compile it in qtcreator. You can also use qmake and make to compile data in the command line.
Method 2: Compile directly in the command line
(1) Go To The qsqlmysql source code directory in QT command prompt. Note that to directly use the Windows console, run the batch file vsvars32.bat to set related environment variables, you can find it in the common7 \ tools directory of Visual Studio.
(2) Compile commands
Qmake "includepath + = D:/development/MySQL/include" libs + = D:/development/MySQL/lib/libmysql. Lib "mysql. Pro
Mingw32-make
4. After compilation is successful, you can find qsqlmysql4.dll and qsqlmysql4.lib under the release directory, and put these two library files in plugins \ sqldrivers under the QT installation directory.
(Blog moving, original post: http://genesislive.sinaapp.com /? P = 32)