Results 1 to 5 of 5

Thread: Link problems with static MySQL plugin

  1. #1
    Join Date
    Sep 2007
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Unhappy Link problems with static MySQL plugin

    I have a little app that uses the SQL module from qt. I can compile (and run) this app fine on Ubuntu (where the qt lib is apparently built without plugins).

    When I first tried my app in Gentoo, it compiled fine, but didn't find the SQL drivers during run-time (since they are compiled as plugins in Gentoo). I tried to convert my app to use the plugin approach (Added Q_IMPORT_PLUGIN to my code and QTPLUGINS to project), but now I get this error during linking:

    g++ -o ../../logind Main.cpp -L../../lib -L/usr/lib/qt4 -lsockets -lssl -lcommon -lsrp -ldotconfpp -L/usr/lib/qt4/plugins/sqldrivers/ -lqsqlmysql -lQtSql -L/usr/lib/mysql -L/usr/lib/qt4 -lQtCore -lz -lm -lrt -ldl -lpthread
    Main.o: In function `StaticqsqlmysqlPluginInstance':
    Main.cpp:71: undefined reference to `qt_plugin_instance_qsqlmysql()'
    collect2: ld returned 1 exit status
    make: *** [../../logind] Error 1
    The offending line in Main.cpp is:

    Qt Code:
    1. Q_IMPORT_PLUGIN(qsqlmysql);
    To copy to clipboard, switch view to plain text mode 

    My project file for the app is:

    Qt Code:
    1. SOURCES += Main.cpp
    2. INCLUDEPATH += ../
    3.  
    4. LIBPATH += ../../lib
    5. LIBS += -lsockets -lssl -lcommon -lsrp -ldotconfpp
    6.  
    7. QT = core sql
    8. QTPLUGIN += qsqlmysql
    9.  
    10. CONFIG += debug
    11.  
    12. TARGET = ../../logind
    To copy to clipboard, switch view to plain text mode 

    I have libqsqlmysql.so in /usr/lib/qt4/plugins/sqldrivers.

    For what it's worth, I use qt 4.3.1 and it was configured with the following:

    ./configure -stl -verbose -largefile -confirm-license -platform linux-g++ -xplatform linux-g++ -no-rpath -prefix /usr -bindir /usr/bin -libdir /usr/lib/qt4 -datadir /usr/share/qt4 -docdir /usr/share/doc/qt-4.3.1-r1 -headerdir /usr/include/qt4 -plugindir /usr/lib/qt4/plugins -sysconfdir /etc/qt4 -translationdir /usr/share/qt4/translations -examplesdir /usr/share/qt4/examples -demosdir /usr/share/qt4/demos -reduce-relocations -no-accessibility -cups -no-xinerama -opengl -no-nis -qt-gif -system-libpng -system-libjpeg -system-libtiff -system-zlib -no-libmng -release -no-separate-debug-info -plugin-sql-mysql -I/usr/include/mysql -L/usr/lib/mysql -no-sql-psql -no-sql-ibase -no-sql-sqlite -no-sql-sqlite2 -no-sql-odbc -qdbus -no-glib -no-qt3support -openssl -no-pch -no-tablet -xrender -xrandr -xkb -xshape -sm -nomake examples
    From what library should `qt_plugin_instance_qsqlmysql()' come from? Or is there something else wrong in my approach?
    Last edited by jacek; 15th September 2007 at 21:06. Reason: changed [code] to [quote]

  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: Link problems with static MySQL plugin

    Your Qt is compiled in shared mode, so you can't use static plugins. You have to use regular plugins. First verify if you have them in your sqldrivers directory. If so, check if you have libmysqlclient installed as the driver won't work without it.

  3. #3
    Join Date
    Sep 2007
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Link problems with static MySQL plugin

    I have the plugin:

    Qt Code:
    1. $ ls /usr/lib/qt4/plugins/sqldrivers/
    2. libqsqlmysql.so
    To copy to clipboard, switch view to plain text mode 

    And I have libmysqlclient:

    Qt Code:
    1. $ ls /usr/lib/libmysqlclient*
    2. /usr/lib/libmysqlclient.so /usr/lib/libmysqlclient.so.15.0 /usr/lib/libmysqlclient_r.so /usr/lib/libmysqlclient_r.so.15.0
    3. /usr/lib/libmysqlclient.so.15 /usr/lib/libmysqlclient.so.15.0.0 /usr/lib/libmysqlclient_r.so.15 /usr/lib/libmysqlclient_r.so.15.0.0
    To copy to clipboard, switch view to plain text mode 

    I re-read the plugins-howto and found some stuff I missed earlier. Do I actually need to load the plugin manually (instead of just linking against it) with QPluginLoader by declaring an interface and writing some wrapper class to it?

    I made this very simple test which I want to get working.

    Test.cpp:
    Qt Code:
    1. #include <QSqlDatabase>
    2.  
    3. int main(int argc, char** argv)
    4. {
    5. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    6. return 0;
    7. }
    To copy to clipboard, switch view to plain text mode 

    Test.pro:
    Qt Code:
    1. SOURCES += Test.cpp
    2. QT = sql
    3. QTPLUGIN = qsqlmysql
    4. TARGET = test
    To copy to clipboard, switch view to plain text mode 

    It compiles fine but I run it and it doesn't find any SQL drivers:

    Qt Code:
    1. $ ./test
    2. QSqlDatabase: QMYSQL driver not loaded
    3. QSqlDatabase: available drivers:
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2007
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Link problems with static MySQL plugin

    I actually managed to get it working. Apparently you need to instantiate QApplication (or in this case QCoreApplication) which actually loads the plugins. Nothing in the plugin documentation explicitly states this, but anyhow this works:

    Qt Code:
    1. #include <QSqlDatabase>
    2. #include <QCoreApplication>
    3.  
    4. int main(int argc, char** argv)
    5. {
    6. QCoreApplication app(argc, argv);
    7.  
    8. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    9.  
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    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: Link problems with static MySQL plugin

    Yes, plugins are loaded in QCoreApplication constructor (I must have missed the lack of QApplication in your previous code, sorry). By the way ".so" is a shared object, not a static plugin, therefore you're using real plugins, not static ones now.

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 10:12
  2. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 14:13
  3. Qt4 win opensource + mysql plugin
    By vr in forum Installation and Deployment
    Replies: 3
    Last Post: 25th May 2007, 09:01
  4. MySql plugin driver issues
    By stevey in forum Installation and Deployment
    Replies: 11
    Last Post: 20th September 2006, 13:45
  5. Problems building mysql plugin for Qt 4.1.2 on windows XP
    By Philip_Anselmo in forum Installation and Deployment
    Replies: 3
    Last Post: 17th May 2006, 15:38

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.