the example of dlsym

Posted rivsidn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了the example of dlsym相关的知识,希望对你有一定的参考价值。

 

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#

 

[email protected]:~/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的主要内容,如果未能解决你的问题,请参考以下文章

[Grid Layout] Use auto-fill and auto-fit if the number of repeated grid tracks is not to be def(代码片段

[转] Dangers of using dlsym() with RTLD_NEXT

AI AND THE BOTTOM LINE: 15 EXAMPLES OF ARTIFICIAL INTELLIGENCE IN FINANCE

LeetCode --- 1281. Subtract the Product and Sum of Digits of an Integer 解题报告

876. Middle of the Linked List

876. Middle of the Linked List