Results 1 to 4 of 4

Thread: How to load library on linux dynamically?

  1. #1
    Join Date
    Aug 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default How to load library on linux dynamically?

    Hello, everyone.
    I have written a library named libtest.so on kubuntu 8.10 with qt 4.4.3.
    Here is its code:
    Qt Code:
    1. extern "C" int sum(int a, int b)
    2. {
    3. return (a+b);
    4. }
    To copy to clipboard, switch view to plain text mode 

    I also wrote a function to load it dynamically (the libtest.so is under the same directory):

    Qt Code:
    1. QLibrary mylib("./libtest");
    2. if (mylib.isLoaded())
    3. // message 1
    4. else
    5. // message 2
    To copy to clipboard, switch view to plain text mode 

    The result is that the library cannot be loaded, as the message 2 is always shown.

    Any suggestion?

    Thank you!
    Last edited by zhehongwang; 4th February 2009 at 02:51.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to load library on linux dynamically?

    J-P Nurmi

  3. #3
    Join Date
    May 2008
    Posts
    155
    Thanked 15 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to load library on linux dynamically?

    Quote Originally Posted by zhehongwang View Post
    Hello, everyone.
    Qt Code:
    1. QLibrary mylib("./libtest");
    2. if (mylib.isLoaded())
    3. // message 1
    4. else
    5. // message 2
    To copy to clipboard, switch view to plain text mode 

    The result is that the library cannot be loaded, as the message 2 is always shown.

    Any suggestion?
    I'd try to add a line
    Qt Code:
    1. mylib.load();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to load library on linux dynamically?

    I think I've found the problem. I should put the libtest.so file under the /lib or /usr/lib, or use ldconfig instead.

    Thanks all

Similar Threads

  1. how does Qt know the library path in LINUX
    By babu198649 in forum General Programming
    Replies: 1
    Last Post: 14th November 2008, 17:10

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.