C语言插件开发模式
作者:网络转载 发布时间:[ 2013/2/26 9:50:48 ] 推荐标签:
p.done();//注意这里done虽然是so中函数。却没有使用使用dlsym找done函数的地址。 err = dlerror(); dlclose(dp);}model1.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dll.h"
void done(){
printf("This is test module 1!
");
}
void init(dll *p){
p->name = (char *)calloc(3, sizeof(char));
strcpy(p->name, "so1");
p->done = done;
}
model1.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dll.h"
void done(){
printf("This is test module 2!
");
}
void init(dll *p){
p->name = (char *)calloc(3, sizeof(char));
strcpy(p->name, "so2");
p->done = done;
}
dll.h 头文件
typedef struct dll{
char * name;
void (*done)() ;
}dll;
以下为gcc的编译过程
gcc -rdynamic -o test test.c dll.h -ldl //-ldl (指定dl库)因为dlopen和dlsym在dl库中
gcc -shared -o module1.so module1.c dll.h
gcc -shared -o $module2.so module2.c dll.h
将会根据输入的不同显调用不同的dll中的函数。

sales@spasvo.com