Building the QMYSQL plugin on Windows using MinGW
From QtCentreWiki
Contents |
[edit] Introduction
The instructions found in Assistant and on doc.trolltech.com does not work when you use the open source version of Qt on Windows with MinGW.
[edit] Prerequisites
- Download the MySQL installer (the essentials msi-package is enough) from MySQL.com and install it (make sure to choose to install the headers as-well.
- Download the mingw-utils (instructions: mingw.org). Copy the contents of the binary tar.gz to %QTDIR%/bin.
[edit] How to Build the Plug-in
- Open a Qt Command Prompt and go to wherever you installed the MySQL server (C:\Program Files\MySQL\MySQL Server 5.0 is the default location).
- Goto the sub-directory lib/opt and run reimp libmysql.lib to produce the liblibmysql.a file. This is the import library to use with MinGW.
- Go to %QTDIR%/src/plugins/sqldrivers/mysql.
- Run the following command: qmake -o Makefile "INCLUDEPATH+=C:\Progra~1\MySQL\MySQLS~1.0\include" "LIBS+=C:\Progra~1\MySQL\MySQLS~1.0\lib\opt\liblibmysql.a" mysql.pro (Notice that the Program Files directory name has been replaced by progra~1. This is because QMake cannot handle spaces in the search paths. Use dir /X <dirname> to find the shorter 8.3 version of the name.)
- Run make - this should build the qsqlmysql.dll and libqsqlmysql.a files in the %QTDIR%/plugins/sqldrivers directory.
- Copy the libmysql.dll file from the MySQL installation's bin directory to a directory in %PATH% (e.g. %QTDIR%/bin).
Now the plug-in should load properly. You may have to empty the plug-in cache before everything works though.
vcp 10:49, 5 January 2010 (CET) Additional Information: For the Qt 4.6.x see documentation in Qt 4.6 SQL Database Drivers, for others useful hints.
[edit] MinGW Tips
If you copy MySQL library and header files directly to the MinGW's lib and inlude directories respectively, the next Qt build will be a bit easier.
This section assumes that MySQL is installed in C:\MySQL, MinGW is installed in C:\MinGW and C:\MinGW\bin is included in PATH environment variable.
Open the command prompt and issue these commands:
cd C:\MySQL\lib reimp -d libmysql.lib dlltool -k --input-def libmysql.def --dllname libmysql.dll --output-lib C:\MinGW\lib\libmysql.a
and copy contents of MySQL's include directory to C:\MinGW\include.
Now when you build Qt, you don't have to specify the any paths to MySQL. So you can simply invoke:
configure -qt-sql-mysql -qt-sql-odbc -qt-sql-sqlite ...
You can use the same method for other libraries.
E8johan 20:32, 6 January 2007 (CET)
