Important: Please read the Qt Code of Conduct -

Problem building mySQl pluggin

  • Hi,

    I have followed all the folowing steps for building MySQL pluging on the page :

    Open the DOS prompt, go to C:\MySQL\MySQL51\lib\opt, and run the following commands:
    reimp -d libmysql.lib
    dlltool -k -d libmysql.def -l libmysql.a
    Open the DOS prompt, go to C:\Qt\4.6.2 and run the following commands:
    configure.exe -debug-and-release -platform win32-g++ -qt-sql-mysql -l mysql -I C:\MySQL\MySQL51\include -L C:\MySQL\MySQL51\lib\opt
    mingw32-make sub-src
    But this is what I get everytime:
    g++ -mthreads -shared -Wl,--out-implib,c:\QtSDK\QtSources\4.8.1\lib\libQtSqld4.a
    -o ....\lib\QtSqld4.dll object_script.QtSqld.Debug -L"c:\QtSDK\QtSources\4.8.
    1\lib" -L"c:\QtSDK\QtSources\4.8.1\lib" tmp\obj\debug_shared\QtSqld_resource_res
    .o -lmysql -LC:\MySQLInstall\Connector-C-6.0.2\lib\opt -lQtCored4
    Creating library file: c:\QtSDK\QtSources\4.8.1\lib\libQtSqld4.a
    ./tmp\obj\debug_shared\qsql_mysql.o: In function codec': C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mysql/qsql_mysql.cpp:223: undefined ref erence tomysql_character_set_name@4'
    ./tmp\obj\debug_shared\qsql_mysql.o: In function qMakeError': C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mysql/qsql_mysql.cpp:234: undefined ref erence tomysql_error@4'
    C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mysql/qsql_mysql.cpp:237: undefined ref
    erence to mysql_errno@4' ./tmp\obj\debug_shared\qsql_mysql.o: In functionqMakeStmtError':
    C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mysql/qsql_mysql.cpp:309: undefined ref
    erence to mysql_stmt_error@4' C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mysql/qsql_mysql.cpp:312: undefined ref erence tomysql_stmt_errno@4'
    ql/qsql_mysql.cpp:358: undefined reference to mysql_stmt_result_metadata@4' ./tmp\obj\debug_shared\qsql_mysql.o:C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mys ql/qsql_mysql.cpp:362: undefined reference tomysql_num_fields@4'
    ql/qsql_mysql.cpp:369: undefined reference to mysql_fetch_field@4' ./tmp\obj\debug_shared\qsql_mysql.o:C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mys ql/qsql_mysql.cpp:432: undefined reference tomysql_free_result@4'
    ql/qsql_mysql.cpp:438: undefined reference to mysql_store_result@4' ./tmp\obj\debug_shared\qsql_mysql.o:C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mys ql/qsql_mysql.cpp:440: undefined reference tomysql_free_result@4'
    ql/qsql_mysql.cpp:437: undefined reference to mysql_next_result@4' ./tmp\obj\debug_shared\qsql_mysql.o:C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mys ql/qsql_mysql.cpp:446: undefined reference tomysql_stmt_close@4'
    ql/qsql_mysql.cpp:452: undefined reference to mysql_free_result@4' ./tmp\obj\debug_shared\qsql_mysql.o:C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mys ql/qsql_mysql.cpp:496: undefined reference tomysql_stmt_data_seek@12'
    ql/qsql_mysql.cpp:498: undefined reference to mysql_stmt_fetch@4' ./tmp\obj\debug_shared\qsql_mysql.o:C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mys ql/qsql_mysql.cpp:513: undefined reference tomysql_data_seek@12'
    ql/qsql_mysql.cpp:514: undefined reference to mysql_fetch_row@4' ./tmp\obj\debug_shared\qsql_mysql.o:C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mys ql/qsql_mysql.cpp:529: undefined reference tomysql_stmt_fetch@4'
    ql/qsql_mysql.cpp:544: undefined reference to mysql_fetch_row@4' ./tmp\obj\debug_shared\qsql_mysql.o:C:\QtSDK\QtSources\4.8.1\src\sql/drivers/mys ql/qsql_mysql.cpp:1511: undefined reference tomysql_real_escape_string@16'
    collect2: ld returned 1 exit status
    mingw32-make[2]: *** [....\lib\QtSqld4.dll] Error 1
    mingw32-make[2]: Leaving directory C:/QtSDK/QtSources/4.8.1/src/sql' mingw32-make[1]: *** [debug-all] Error 2 mingw32-make[1]: Leaving directoryC:/QtSDK/QtSources/4.8.1/src/sql'
    mingw32-make: *** [sub-sql-make_default-ordered] Error 2


    pleeeeease help :(


  • I think, you link against the 64 bit dll from mysql. I got the same errors.
    When you install mysql libs, there is a combo box in the setup, where you can select to install the 32 bit version.

  • Hi Gerolf,

    I downloaded and installed the 32 bit version of the connector using the installer "mysql-connector-c-6.0.2-win32.msi" but getting the same errors as above. Also this installer didn't provide a combo box for selecting 32 bit version.

    Can u share the installer that you had used to install 32 bit version. U can send it at



  • Hello Ziaddin,

    You are gonna need to stick to the 32 bit version of everything for MySql. I have an article that I will link this evening for you that should get you going (Sorry, left my laptop at home because it's compiling the open source version of Qt). I had a lot of trouble building this driver until I found this article I will be linking later.

  • I had enormous problems with installing this driver. I have been suggested to download the latest MSI version of MySql connector 6xxx/C. I almost sure it was 32-bit version. I did not have to run either reimp or dlltoo. I went straight to configure.exe and mingw32-make. I used MinGW 4.7.0. Two things I did that are not in documentation:

    • run command line as Administrator
    • used configure with option -spec mingw32-g46 (or something like this)

    I am not sure about the last command. I'll let you know as soon as I can.

  • Thanx weblife :)

    It worked :)

    I am sorry for the late reply.

    How ever now I get QSqlError(2003, "QMYSQL: Unable to connect", "Can't connect to MySQL server on 'localhost' (10061)")

    code for connection is :
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    if (! {
    QMessageBox::critical(0, tr("Cannot open database"),
    tr("Unable to establish a database connection.\n"
    "This example needs SQLite support. Please read "
    "the Qt SQL driver documentation for information how "
    "to build it."), QMessageBox::Cancel);

    Edit: please use @ tags around code sections; Andre

  • @Ziaddin Good news! Sorry it has taken me so long also, semester just started and trying to finish project I started so I can focus back on school. I am at work now and noticed your post and will have to get back to you tomorrow.

    In the meantime can you please edit your post so your code shows its formatted output. To do this either add the @ symbol to the beginning and end of the coded area.

    PS: Just to note I am pretty sure your syntax has a issue but will go over later. Another issue could be your remote access authorities, check to make sure you don't need to grant your IP access from mysql remote manager.

  • *@*Ziaddin Your code looks okay. I am almost certain it is your MySql or server settings. I would suggest checking port numbers usernames and passwords. Also be sure you posting passwords and user info that is fake for your own safety. I personally use my web host MySql database so I am not the one to guide you on local settings.


    I say keep it easy when first experimenting with everything and break down each step, including variables. This is how I would do it.

    @ QString dbHost = "";
    QString dbName = "databaseName";
    QString dbUser = "databaseUser";
    QString dbPass = "databasePassword";
    qint16 dbPort = 3306; // Changes per host settings.

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    if ({
        qDebug() << "Yeah!!!!";
    } else{
        qDebug() << db.lastError().text();

    I don't know if this matters but I would would use the ordered functions I demonstrate because it could be that also, maybe? I wrote mine like I was logging in to the system step by step.

Log in to reply