Compile MySQL plugin for Qt

  • Hello,
    first, sorry about the topic 20mins ago, I messed up with the versions...
    I'll try to be as comprehensible as possible (I'm not a native english speaker).

    I just downloaded the SDK 1.1, with Qt Creator 2.1.
    Inside it, there is no MySQL driver; I know I have to compile it myself.

    My question is:
    Can't I compile this libmysql.a from the pack I just downloaded ? or do I have to download the Qt sources, compile them with the mysql options and all that just to get the libmysql.a.

    ps: I can't try "this":, since there is no in the SDK 1.1

    [updated the title, Tobias]

  • As I said in the other thread, you need to rebuild Qt to enabled MySQL support. This is more easily done by downloading the stand-alone Qt source package rather than trying to rebuild the Qt that ships as part of the SDK.

    Go to "the download site": and from the right hand side labelled "Qt: Framework Only" and download the source for your platform and follow my instructions in the previous thread.

  • You can install the sources right from the SDK. Just start the Maintain Qt SDK application and choose to install the sources from there. You only need to compile the driver itself, not the whole of Qt.

  • If you do it that way I think you will also need to install perl. The last time I checked the sources that shipped with the SDK did not have the camelcased headers generated and so the configure step tries to run the synqt perl script to create them.

  • Ok thanks you two. This answer my question.

    I downloaded the sources using the Maintain Qt Application and installed PERL

    Following "this":, I did this:
    @configure -platform win32-g++ -static -release -qt-sql-mysql -l mysql -I "C:\Program Files\MySQL\MySQL Server 5.5\include" -L "C:\Program Files\MySQL\MySQL Server 5.5\lib"@

    It seems to work but after, the mingw32-make command fails because of the space in the paths...

    @g++: Files\MySQL\MySQL: No such file or directory
    g++: Server: No such file or directory
    g++: 5.5\lib: No such file or directory@

    It's getting on my nerve, so I'll try again tomorrow...

    By the way, I'm recompiling the full Qt here, is there a way to recompile only the myqsl driver ?

  • What you can do, is create an "NTFS symlink or junction": with a path that does not contain spaces, and use that path instead.

  • Or in the future install MySQL (and other libs) to a location that does not have spaces in the path after being bitten by this many times before ;-)

  • Meanwhile, I hope that at one point, the whole tool chain will be fixed so it simply accepts spaces in paths.

  • Yes. You would hope this is simple in the 21st century. No such luck yet though.

  • Thanks a lot guys!
    I finally made it after wasting 2 days to compile this MySQL driver.

    At first I was compiling the whole sources... It took 3 hours each time.
    Then I found that the Qt sources downloaded from the QT Maintain Application were not complete.
    And after a big headache,
    here is how I did it: (it might interest someone)

    • Download Qt SDK and install (C:\QtSDK)
    • Download mingw-utils and extract to C:\QtSDK\Desktop\Qt\4.7.3\mingw\bin
    • Put the C:\QtSDK\Desktop\Qt\4.7.3\mingw\bin in the %PATH%
    • Download Qt Sources and extract them (C:\QtSrc)
    • Download and install a perl compiler (like ActivePERL)
    • Install MySQL headers and libs in a path without spaces (C:\MySQL)

    Open a Command Prompt
    @set QTDIR=C:\QtSrc

    cd %MYSQLDIR%\lib
    reimp libmysql.lib
    dlltool -k --input-def libmysql.def --dllname libmysql.dll --output-lib %QTDIR%\src\plugins\sqldrivers\mysql\libmysql.a

    cd %QTDIR%\src\plugins\sqldrivers\mysql
    qmake -o Makefile "INCLUDEPATH+=%MYSQLDIR%\include" "LIBS+=%MYSQLDIR%\lib\liblibmysql.a"

    Then copy libmysql.dll (from %MYSQLDIR%\lib) to any folder in the %PATH%
    Copy %QTDIR%\plugins\sqldrivers\qsqlmysql4.dll & qsqlmysqld4.dll to C:\QtSDK\Desktop\Qt\4.7.3\mingw\plugins\sqldrivers

    and it should be ok.

    This seems so simple afterwards... =)

  • Glad you got it working. Good luck with the rest of your project.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.