{
int f();
int f()
{
A a;
a.gt();
a.pt();
return 0;
}
}
編譯命令:
gcc -shared -o sec.so secso.cpp -L. -lmy
這時候生成第二個.so文件,此時庫從一個類變成了一個c的接口.
拷貝到/usr/lib
下面開始調用:
//test.c
#include "stdio.h"
#include "dlfcn.h"
#define SOFILE "sec.so"
int (*f)();
int main()
{
void *dp;
dp=dlopen(SOFILE,RTLD_LAZY);
f=dlsym(dp,"f");
f();
return 0;
}
編譯命令如下:
gcc -rdynamic -s -o myapp test.c
運行Z$./myapp
10
$