Building the QMYSQL plugin on Windows using MinGW
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.
- 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: oldwiki.mingw.org). Copy the contents of the binary tar.lzma or tar.gz to %QTDIR%/bin.
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.
NOTE: If you are using Windows Vista or Windows 7, you must run the command prompt as Administrator to be able to produce or copy the needed files
- 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 qsqlmysql4.dll, libqsqlmysqld4.dll, qsqlmysql4.a and libqsqlmysqld4.a files in the %QTDIR%/plugins/sqldrivers directory.
NOTE: If you don't have make, you may use the make provided by mingw (e.g.: mingw32-make.exe)
- 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.
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)