In order to port a Qt application to Windows, I'm trying to somehow build the MySQL driver (QMYSQL) into the Windows Qt build.
I built Qt by downloading the sources (4.8.1 in this case), "configure" and "mingw32-make" - but the only database driver that's available in this build is QSLite (QSQLITE).
So googling around, I found a couple of howtos, like "How to build the MySQL driver for MinGW users", which states a qmake command (after explaining how to rebuild all of Qt, including "reimp", "dlltool" and some sql-related configure options, which didn't really seem to have any effect at all) that contains the MySQL include directory, but not the MySQL lib directory and trying "make" afterwords fails (Qt build dir replaced with $QTDIR):
So I ran "make distclean" to clean this up and used another qmake command:g++: error: mysql: No such file or directory
make[1]: *** [..\..\..\..\plugins\sqldrivers\qsqlmysql4.dll] Error 1
make[1]: Leaving directory `$QTDIR/src/plugins/sqldrivers/mysql
'
make: *** [release] Error 2
$MYSQLDIR is the equivalent of "C:\MySQL\MySQL51", $MYSQLDIR/include contains files like mysql.h and $MYSQLDIR/lib contains files like libmysql.a and libmysql.dll (but no "opt" directory, mentioned in step 8). Those files were created by running the "reimp" and "dlltool" commands (link to mingw-utils tarball containing reimp.exe).qmake "INCLUDEPATH+=$MYSQLDIR/include" "LIBS+=-L$MYSQLDIR/lib" mysql.pro
The qmake command created 3 makefiles: Makefile, Makefile.debug and Makefile.release
I then ran "make" and it successfully created qsqlmysql4.dll in plugins/sqldrivers (and qsqlmysqld4.dll, libqsqlmysql4.a, libqsqlmysqld4.a).
My Qt application still didn't load the MySQL driver and I didn't know why.
Then somebody told me to set the environment variable "QT_DEBUG_PLUGINS" to "1" before running my application (unfortunately this isn't mentioned in the howto page, or anywhere else it seems).
That way I got some helpful information (on standard error) - an error message for every a file and dll file, which looks like this:
Apparently the Qt build I'm using was built in release mode (although debug is supposed to be the default and I'm sure I didn't say "configure -release") and the MySQL plugin was built in debug mode. Since there are targets called "release..." in the new makefiles, I just ran "make clean" and "make release", which created new files that didn't seem to be any different.QFactoryLoader::QFactoryLoader() looking at "$QTDIR/plugins/sqldrivers/
qsqlmysqld4.dll"
In $QTDIR/plugins/sqldrivers/qsqlmysqld4.dll:
Plugin uses incompatible Qt library expected build key "Windows mingw release full-config", got "Windows mingw debug full-config"
So I ran "make distclean" (removed all 4 mysql a/dll files and the mysql makefiles created by qmake), ran the same qmake command again and then "make release", now I get a new error message:
- What does this mean? The file exists, so I don't know what else it's looking for.QFactoryLoader::QFactoryLoader() looking at "$QTDIR/plugins/sqldrivers/qsqlmysql4.dll"
QLibraryPrivate::loadPlugin failed on "$QTDIR/plugins/sqldrivers/qsqlmysql4.dll" : "Cannot load library $QTDIR/plugins/sqldrivers/qsqlmysql4.dll: The specified module could not be found."
"Cannot load library $QTDIR/plugins/sqldrivers/qsqlmysql4.dll: The specified module could not be found."
could not load
- Is there a complete documentation page that actually works?
EDIT/SOLVED:
I figured it out afterall - $MYSQLDIR/lib/libmysql.dll has to be in the PATH (or in the application directory).
I'm not going to delete this thread now, maybe it'll help somebody else save some time...QSqlDatabase: available drivers: QSQLITE QMYSQL3 QMYSQL
Bookmarks