- 建立
先编写一个可运行的c文件,包含需要使用的函数。
//tt.c
#include<stdio.h>
int test(){
printf(“11111”);
}
再使用gcc tt.c -fPIC -shared -o libtt.so命令 将add文件编译成名为libtt.so
形势的动态链接库
2.使用
#include<stdio.h>
#include<dlfcn.h>
int main(){
void *handle;
int (*test)();
handle=dlopen("/home/du/libtt.so",RTLD_LAZY);
if(!handle){
printf("%s",dlerror());
exit(1);
}
test = dlsym(handle, “test”);
if(!handle){
printf("%s",dlerror());
exit(1);
}
test();
}