Results 1 to 5 of 5

Thread: HOW TO - created and use shared library (.so)

  1. #1
    Join Date
    Nov 2006
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default HOW TO - created and use shared library (.so)

    Hi all,

    I've created my own shared library and tried to load it dynamically while my small test app is running. Unfortunately it's not working - the lib is not loaded!

    In the .pro file for my lib:
    Qt Code:
    1. TEMPLATE = lib
    2. CONFIG += dll
    3. TARGET = mylib
    To copy to clipboard, switch view to plain text mode 
    In the header file for my lib:
    Qt Code:
    1. #include <Qt/qglobal.h>
    2.  
    3. #ifdef TEST_LIB
    4. # define TEST_EXPORT Q_DECL_EXPORT
    5. #else
    6. # define TEST_EXPORT Q_DECL_IMPORT
    7. #endif
    8.  
    9. class TEST_EXPORT DBConnection
    10. {
    11. ...
    12. };
    To copy to clipboard, switch view to plain text mode 

    Is there somthing else what I need to do?

    Then in my test app I call the lib:
    Qt Code:
    1. QLibrary myLib("mylib");
    To copy to clipboard, switch view to plain text mode 
    If I check it with
    Qt Code:
    1. myLib.isLoaded()
    To copy to clipboard, switch view to plain text mode 
    then I can see that the lib is not loaded.
    Maybe it can't find the lib? Where I have to put my lib that its beeing loaded?

    Any help would be great!!
    Many thanks and best regrads
    big4mil

  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 - created and use shared library (.so)

    You could place it in the same directory as the main binary.

    I might be wrong here, but I think you need to wrap your methods in 'extern "C"' statements if you want to resolve symbols dynamically. And you'll need factory functions to create instances of your class.

  3. #3
    Join Date
    Nov 2006
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: HOW TO - created and use shared library (.so)

    Hi wysota,

    many thanks for your response. My lib is in the same directoy as the app is. I develop under SUSE Linux 10.1.

    Can you give me please one simple example on how to do this? I have never done this bevor. Would be great.

    What do you mean with:
    And you'll need factory functions to create instances of your class.
    Many thanks
    big4mil

  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 - created and use shared library (.so)

    See the C++ dlopen mini-howto for details. QLibrary uses dlopen internally so everything there applies.

  5. #5
    Join Date
    Nov 2006
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: HOW TO - created and use shared library (.so)

    that's fine - thanks for the link...I'll check that out!!


    big4mil

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.