首页 > 其他 > 详细

the example of dlsym

时间:2018-09-13 13:36:53      阅读:193      评论:0      收藏:0      [点我收藏+]

 

void    *handle;
int     i, (*fptr)(int);


/* open the needed object */
handle = dlopen("/usr/home/me/libfoo.so", RTLD_LOCAL | RTLD_LAZY);


/* find the address of function and data objects */
*(void **)(&fptr) = dlsym(handle, "my_function");
iptr = (int *)dlsym(handle, "my_object");


/* invoke function, passing value of integer as a parameter */
(*fptr)(i);

 

有关 *(void **)(&fptr) 为什么不直接 fptr 的解释可以参考下边连接:

https://stackoverflow.com/questions/29184745/what-does-void-funcp-do-in-this-line-of-code-involving-dlsym#

 

yuchao@ubuntu:~/demo/C/glibc_demo/dlsym$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.

这个编译器用直接用 fptr 也是没问题的。

 

the example of dlsym

原文:https://www.cnblogs.com/rivsidn/p/9639737.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!