Home > Qt > Using MySQL with Qt (QMYSQL module)

Using MySQL with Qt (QMYSQL module)

The Qt documentation states:

How to Build the QMYSQL Plugin on Windows

You need to get the MySQL installation files. Run SETUP.EXE and choose “Custom Install”. Install the “Libs & Include Files” Module. Build the plugin as follows (here it is assumed that MySQL is installed in C:\MySQL):


 cd %QTDIR%\src\plugins\sqldrivers\mysql

 qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\MySQL Server <version>\lib\opt\libmysql.lib" mysql.pro

 nmake

If you are not using a Microsoft compiler, replace nmake with make in the line above.

If there are spaces in your include path, it won’t work. The easiest solution for me was to use the 8.3 directory names for all directories containing spaces. You can find out the 8.3 name of a directory by using the dir /x command, for instance:


dir /x "C:\Program Files"

So your qmake command could look something like this:

qmake -win32 "INCLUDEPATH+=C:\Progra~1\MySQL\MYSQLS~1.1\include" "LIBS+=C:\Progra~1\MySQL\MYSQLS~1.1\lib\opt\libmysql.lib" mysql.pro

Then just run nmake, it should work.

Other issues:

In case you get the nmake error that winver.h is not found, you may copy it from the VS PlatformSDK directory, e.g.:

D:\VS_2005\VC\PlatformSDK\Include

If you get more errors, like cl.exe is missing mspdb80.dll go to

D:\VS_2005\VC

and execute

vcvarsall.bat

t0 set the needed paths.

Warning: vcvarsall will not set the environment permanently, at least it doesn’t do that for me. So call it from the current console session right before you execute nmake.

About these ads
Categories: Qt Tags: , ,
  1. Arthur
    April 12, 2012 at 1:21 pm | #1

    After the second command gives
    WARNING (internal):1: Unescapted backslashes are deprecated.
    WARNING (internal):1: Unescapted backslashes are deprecated.
    WARNING (internal):1: Unescapted backslashes are deprecated.

    And after the nmake gives
    LINK : warning LNK4001: no object files specified; libraries used
    LINK : warning LNK4068: /MACHINE not specified; defaulting to X86
    LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
    debug\mysql.exe : fatal error LNK1120: 1 unresolved externals
    NMAKE : fatal error U1077: ‘”C:\Program Files (x86)\Microsoft Visual Studio 9.0\
    VC\BIN\link.EXE”‘ : return code ’0×460′
    Stop.
    NMAKE : fatal error U1077: ‘”C:\Program Files (x86)\Microsoft Visual Studio 9.0\
    VC\BIN\nmake.exe”‘ : return code ’0×2′
    Stop.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.