Results 1 to 4 of 4

Thread: symbol lookup error when using plugins

  1. #1
    Join Date
    Jul 2006
    Location
    Poprad/Prague
    Posts
    33
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question symbol lookup error when using plugins

    Hello!

    I'm trying to make an application which should be extensible using (lower-level, as guys from Trolltech call it) plugins.

    I want to access the methods of my own classes in the plugin, which is a source of my problems. I can access methods of Qt classes in a plugin (if they are passed as a parameter), but I can not use methods of my class (although it is passed as a parameter, too).

    When I found out that sth is wrong with the plugin system, I tried to modify the Plug&Paint example (to make sure if I didn't mess up sth with plugins), but that didn't work neither.

    so here is what I have in a header file:
    Qt Code:
    1. class myClass : public QObject {
    2. Q_OBJECT
    3. public:
    4. int sayHello(int a);
    5. };
    To copy to clipboard, switch view to plain text mode 

    and the in a cpp file:
    Qt Code:
    1. #include "myClass.h"
    2.  
    3. int myClass::sayHello(int a){
    4. a += 30;
    5. return a;
    6. }
    To copy to clipboard, switch view to plain text mode 

    I'm using slightly modified interfaces.h:
    Qt Code:
    1. ...
    2. class FilterInterface
    3. {
    4. public:
    5. virtual ~FilterInterface() {}
    6.  
    7. virtual QStringList filters() const = 0;
    8. --> virtual QImage filterImage(const QString &filter, const QImage &image, myClass &cla, QWidget *parent) = 0;
    9. };
    10. ...
    To copy to clipboard, switch view to plain text mode 

    and in the plugin code (basictools.cpp):
    Qt Code:
    1. QImage BasicToolsPlugin::filterImage(const QString &filter, const QImage &image, myClass &cla, QWidget * /* parent */)
    2. { int b = 50;
    3. --> int a = cla.sayHello( b );
    4. QImage result = image.convertToFormat(QImage::Format_RGB32);
    To copy to clipboard, switch view to plain text mode 

    Everything compiles fine, but I get an error at runtime (when invoking a filter):
    Qt Code:
    1. symbol lookup error: /home/.../bin/plugins/libpnp_basictools_debug.so: undefined symbol: _ZN7myClass8sayHelloEi
    To copy to clipboard, switch view to plain text mode 

    I've looked up here on the forum, but I didn't find a topic about it, so could you please help me or just a post a link where sth like this is explained?

    Thanx.
    PS: I think it is the same problem as had a guy here, but nobody replied to him...:/
    PS2: Compiling on Slack 10.2 with gcc 3.3.6 and Qt 4.1.3

  2. The following user says thank you to macbeth for this useful post:

    darkadept (30th August 2007)

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

    Default Re: symbol lookup error when using plugins

    Where is "myClass" defined (I mean the body of the class)? In the main application or in the plugin? If it is defined in main application, then you have just found your problem. Plugins (by default) can't resolve symbols by looking them up in the main app. The app has to export them explicitly so that the plugin can find them. There are two ways of doing that -- fast or proper...

    1. Fast method (tested only under Linux/GCC, should work under Unices/GCC, doesn't work under Win32/MinGW)
    GCC has a switch to enable exporting symbols for dynamic linkage. You have to pass "-rdynamic" flag to the linker. You can achieve that by setting "QMAKE_LFLAGS += -rdynamic" in your project file

    2. Proper method (works everywhere and is used in 90% of all cases)
    Extract all the symbols (classes, functions) from the main application which are to be made available to the plugins and create a standalone shared library (using TEMPLATE = lib) and then link both the application and plugins agains it (LIBS += -lnameoflib)

    There is also a third method, very crude but effective if the number of symbols needed by the plugin is very small -- simply copy the sources of those symbols from the main application to your plugin and compile them into the plugin statically.

  4. The following 2 users say thank you to wysota for this useful post:

    darkadept (30th August 2007), macbeth (29th July 2006)

  5. #3
    Join Date
    Jul 2006
    Location
    Poprad/Prague
    Posts
    33
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: symbol lookup error when using plugins

    To answer the question, yes, the myClass is defined in a main application. So you gave me the solution, thanks a lot.
    I've just tried the -rdynamic flag and it works, the second way--I'm sure--also will.

    I just wanted to know what is the 'standard' of doing that...

    Thanks...

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

    Default Re: symbol lookup error when using plugins

    Quote Originally Posted by macbeth
    I just wanted to know what is the 'standard' of doing that...
    The standard is deploying a library with symbols that need to be exported.

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

    darkadept (30th August 2007)

Similar Threads

  1. Qt4 Plugins How-to
    By Chaid in forum Qt Programming
    Replies: 4
    Last Post: 8th July 2006, 08:32

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.