23,125
社区成员
发帖
与我相关
我的任务
分享
/* 主函数 */
#include <dlfcn.h>
#include <assert.h>
#include <stdio.h>
short (*p_short_fun)(short);
short *p_short_var;
int main(int argc, char *argv[])
{
void *h;
short n;
h = dlopen("libshort.so", RTLD_LAZY);
assert(h != NULL);
p_short_fun = dlsym(h, "short_fun");
assert(p_short_fun != NULL);
n = p_short_fun(8);
printf("%d\n", (int)n);
n = (*p_short_fun)(8);
printf("%d\n", (int)n);
p_short_var = dlsym(h, "short_var");
assert(p_short_var != NULL);
n = *p_short_var;
printf("%d\n", (int)n);
return 0;
}
/*
* libshort.c
* 用下面的命令编译成libshort.so
* gcc -shared -o libshort.so libshort.c
*/
short short_var = 12345;
short short_fun(short x)
{
return x * 2;
}