linux c++编程怎么样导出.so中的类呢。能否给个详细的例子
来源:百度知道 编辑:UC知道 时间:2024/05/16 02:12:11
#include <stdio.h>
#include <iostream>
#include <dlfcn.h>
using namespace std;
int main(void)
{
void *handle=NULL;
string (*pQueryAll)();
handle=dlopen("./db.so",RTLD_NOW);
if(handle==NULL)
{
cout<<"failed loading library!"<<endl;
return -1;
}
下面我要怎么写呢. 我想用到.so里的一个叫Tblstore类,因为里面有好多方法
要怎么写啊, 静态的话直接声明这个类就行了.这里不知道怎么写
return 0;
}
#include <iostream>
#include <dlfcn.h>
using namespace std;
int main(void)
{
void *handle=NULL;
string (*pQueryAll)();
handle=dlopen("./db.so",RTLD_NOW);
if(handle==NULL)
{
cout<<"failed loading library!"<<endl;
return -1;
}
下面我要怎么写呢. 我想用到.so里的一个叫Tblstore类,因为里面有好多方法
要怎么写啊, 静态的话直接声明这个类就行了.这里不知道怎么写
return 0;
}
(1)先include相关头文件
(2)编译的时候g++加上-l选项,链接上相关的库,例库的文件是libtest.so, g++ 你的文件.cpp -ltest即可
你要有个头文件声明那个类,最好是跟库一起发行的头文件