Results 1 to 5 of 5

Thread: creating a dylib for a plugin with external classes

  1. #1
    Join Date
    Jul 2007
    Location
    New York
    Posts
    45
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default creating a dylib for a plugin with external classes

    I am able to create a plugin interface and link it, and the pluginLoader likes it, but if I try to include any classes from my main app, it won't link.

    I would really like something like:


    Qt Code:
    1. #include <C.h>
    2.  
    3. class A : public AInterface
    4. {
    5. public:
    6. C *instance() { return new B(); }
    7. };
    8.  
    9. class B : public C
    10. {
    11. B() {}
    12. };
    13.  
    14. Q_EXPORT_PLUGIN2(app_A, A)
    To copy to clipboard, switch view to plain text mode 

    but I cannot figure out a way to get C.o to link when I create the dylib. It doesn't seem to make sense to add a LIBS line to the .pro that points to the .o file in:

    [objectsdir]/Release/*build/Objects-normal/i386/C.o

    because it doesn't feel right -- if I change machines, OSs, or distros it will break.

    How do I get this link to work?
    Last edited by themolecule; 21st August 2007 at 06:03.

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

    Default Re: creating a dylib for a plugin with external classes

    There are two ways of doing it. The less proper but easier way is to ask your compiler to allow dynamically loaded objects to resolve their symbols using the main application. For GCC it is done by adding a linker flag (I don't remember now what exactly). The other solution (preferred) is to export all the symbols you may want to use from the plugin into a separate library and link both the application and the plugin against the library.

  3. #3
    Join Date
    Jul 2007
    Location
    New York
    Posts
    45
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: creating a dylib for a plugin with external classes

    Any idea what flag this is?

    Do I add it in the .pro or do I need to do something in the xcode project preferences?

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

    Default Re: creating a dylib for a plugin with external classes

    The flag is -rdynamic, as far as I remember. You have to pass it to the linker in whatever way you see fit.

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

    themolecule (23rd July 2008)

  6. #5
    Join Date
    Jul 2007
    Location
    New York
    Posts
    45
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: creating a dylib for a plugin with external classes

    On osx, the .pro settings seem to be

    QMAKE_LFLAGS += "-undefined"
    QMAKE_LFLAGS += "dynamic_lookup"

    but I never could get the symbols to be resolved from the main app. I think another flag in the main app would expose the symbols to make the dynamic lookup succeed.

    Either way, the preferred solution you mentioned works! Thanks!

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. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04

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.