PDA

View Full Version : How to load library on linux dynamically?



zhehongwang
4th February 2009, 02:44
Hello, everyone.
I have written a library named libtest.so on kubuntu 8.10 with qt 4.4.3.
Here is its code:

extern "C" int sum(int a, int b)
{
return (a+b);
}

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


QLibrary mylib("./libtest");
if (mylib.isLoaded())
// message 1
else
// message 2

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

Any suggestion?

Thank you!:)

jpn
4th February 2009, 11:28
QLibrary::errorString()

ktk
4th February 2009, 22:50
Hello, everyone.

QLibrary mylib("./libtest");
if (mylib.isLoaded())
// message 1
else
// message 2

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
mylib.load();

zhehongwang
5th February 2009, 08:35
I think I've found the problem. I should put the libtest.so file under the /lib or /usr/lib, or use ldconfig instead. :o

Thanks all