create and use shared library in qt
Hi everyone,
I tried to create and use a shared library in qt.I used the c++ library project to create this.
code used to create a shared library:
.pro file:
Code:
QT -= gui
TARGET = myLIB
TEMPLATE = lib
DEFINES += MYLIB_LIBRARY
SOURCES += mylib.cpp
HEADERS += mylib.h\
myLIB_global.h
.h file
Code:
class MYLIBSHARED_EXPORT MyLIB {
public:
MyLIB();
int add(int x,int y);
};
extern "C"
{
int sub(int x,int y);
}
.cpp file :
Code:
MyLIB::MyLIB()
{
}
int MyLIB::add(int x, int y)
{
return x+y;
}
int sub(int x, int y)
{
return x-y;
}
In my test application i am able to use sub function.code is
Code:
typedef int (*pf)(int,int);
pf fun
=(pf
)QLibrary::resolve("./libmyLIB.so",
"sub");
int x=fun(20,10);
It is working.
But when i am trying to use isLoaded function it is returning false.
Code:
ok=myLib.isLoaded();
My problem is i want to use the function directly without using QLibrary.(only adding in .pro file)
How i will use add function in my application ?
Re: create and use shared library in qt
See in the qmake documentation for LIBS, include the header file of your library and use your library classes as usual.
Re: create and use shared library in qt
thanks for reply.Can you tell me what should be written in .h file.One prototype or any thing extra.
Re: create and use shared library in qt
In your case you probably only have to use
Re: create and use shared library in qt