Results 1 to 8 of 8

Thread: How to use static mysql plugin

  1. #1
    Join Date
    Jan 2009
    Posts
    8
    Thanks
    1

    Unhappy How to use static mysql plugin

    All

    After googling failed, I am about to give up using static QT plugin. I hope someone who had solve this problem or know quickly and can point out what I am doing wrong. Here is a bit about the background.

    I am trying to use the mysql driver offer in qt 4.4.x. I can successfull compile a version of shared QT and able to use the QSqlDatabase classes to work with the database. This work perfect .

    However, I would like to compile the mysql driver and plugin into my application, this open up for the need to use static mysql driver. I followed the help and ran ./configure with -static and -qt-sql-mysql -plugin-sql-mysql -I/usr/include/mysql -L/usr/lib/mysql ... and a few more switches. The result is a libsqlmysql.a in the !QT/plugins/sqldrivers/*

    My project file is set up as follow:

    Template = app
    TARGET = executable
    QT += core sql
    CONFIG += static
    QTPLUGIN += qsqlmysql

    source += main.cpp


    The source file is as follow:



    #include <QtCore>
    #include <QSqlDatabase>
    #include <QtPlugin>

    QT_IMPORT_PLUGIN( qsqlmysql )

    int main( int argc, char** argv )
    {
    QCoreApplication app( argc, argc );

    QSqlDatabase db = QSqlDatabase::addDatabase( "MYSQL" );

    return 0;
    }

    all of this is a simple exercise to load the SQL driver.

    Here is the problem .

    When compiling with the QT_IMPORT_PLUGIN I have multiple problem including "undefined reference to mysql_server_end" together with many other sql_ related function .

    if I take off the QT_IMPORT_PLUGIN then the it compile fine, the exec is large which suggested that it compiled the qsqlmysql static lib into it. However, at run time, it complain of no MYSQL driver loaded .

    Through out googling, I see many question like this and the common solution is recompile and use it as share object. I really need to know a correct setup of static object and hope that this will be the answer for many other to come.

    If you know the answer, please help, I am sure that many other are waiting for the answer as well..

    OS is redhat
    compiler is g++

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use static mysql plugin

    Do you have those static plugins built?

  3. #3
    Join Date
    Jan 2009
    Posts
    8
    Thanks
    1

    Default Re: How to use static mysql plugin

    hey thanks for replying,

    I do have the -qt-sql-mysql driver and plugin specified. all seems correct.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use static mysql plugin

    I'm asking if the static plugin file is the sqldrivers directory. BTW. -qt-sql-mysql and -plugin-sql-mysql are exclusive. The first compiles mysql support directly into Qt library whereas the second one builds a static plugin. Please check if any of your Qt libraries depends on the mysql client library.

  5. #5
    Join Date
    Jan 2009
    Posts
    8
    Thanks
    1

    Default Re: How to use static mysql plugin

    ah, sorry about that,

    according to the documentation, it seems that I do. I have the libqsqlmysql.a in the plugin/sqldrivers directory.

  6. #6
    Join Date
    Jan 2009
    Posts
    8
    Thanks
    1

    Default Re: How to use static mysql plugin

    Being a newbies I don't know how to check if any library depends on mysqlclient. after reading other forum, I assume that it does, other suggested to include -L/usr/lib/mysql -lmysqlclient

    after doing that, I have a different error:
    " /usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.so when searching for -lmysqlclient
    /usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.a when searching for -lmysqlclient
    /usr/bin/ld: cannot find -lmysqlclient"

    I checked and there exist under /usr/lib/sql both the libmysqlclient.so and .a

    this stuff is beyond my knowledge, I hope you can help.

    thanks

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use static mysql plugin

    Run ldd on every Qt library (QtCore and QtSql being the most obvious ones) and see if "libmysqlclient" is there.

  8. The following user says thank you to wysota for this useful post:

    khikho (19th January 2009)

  9. #8
    Join Date
    Jan 2009
    Posts
    8
    Thanks
    1

    Talking Re: How to use static mysql plugin

    I finally figured this out, for future user, here is correct way to do this step by step:

    How to use static plugin in qt: example for mysql

    1) ./configure -static -plugin-sql-mysql ... and many other switch as you wish,

    2) make sure your project file look as follow:

    Template = app
    TARGET = executable
    QT += core sql
    CONFIG += static
    QTPLUGIN += qsqlmysql
    LIBS += -L/usr/lib64/mysql -lmysqlclient ( use /usr/lib/mysql for 32 bit system )
    source += main.cpp


    3) make sure your file have the macro that look as followed:

    #include <QtCore>
    #include <QSqlDatabase>
    #include <QtPlugin>

    QT_IMPORT_PLUGIN( qsqlmysql )

    int main( int argc, char** argv )
    {
    QCoreApplication app( argc, argc );

    QSqlDatabase db = QSqlDatabase::addDatabase( "MYSQL" );
    qDebug() << QSqlDatabase::drivers();


    return 0;
    }


    This will give you a working example to push ahead.



    4) for using mysql driver as share object, just recompile qt as follow
    ./configure -qt-sql-mysql ... and many other switch

    5) use QSqlDatabase as in step 3 without the PLUGIN macro.
    Last edited by khikho; 19th January 2009 at 23:05.

Similar Threads

  1. How build mysql plugin
    By MrShahi in forum Installation and Deployment
    Replies: 5
    Last Post: 8th June 2008, 00:11
  2. Replies: 16
    Last Post: 23rd May 2008, 10:12
  3. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 14:13
  4. Qt4 win opensource + mysql plugin
    By vr in forum Installation and Deployment
    Replies: 3
    Last Post: 25th May 2007, 09:01
  5. MySql plugin driver issues
    By stevey in forum Installation and Deployment
    Replies: 11
    Last Post: 20th September 2006, 13:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.