Compile the MySQL driver of QT in Windows

Source: Internet
Author: User
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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.