24,854
社区成员
发帖
与我相关
我的任务
分享
int main(int argc, char* argv[]){
int a = myint();
return a;
}
int myint(){
int a=0;
a=a+1;
return a;
}
int main(int argc, char* argv[]){
//加载 第三方动态链接库
dlopen("./libTest.so", RTLD_LAZY); //汇编跟踪(s 或者 si )在此就跟踪不下去了。
int a = myint();//第三方 动态链接库提供的函数
return a;
}
EXAMPLE
Load the math library, and print the cosine of 2.0:
#include <stdio.h>
#include <dlfcn.h>
int main(int argc, char **argv) {
void *handle;
double (*cosine)(double);
char *error;
handle = dlopen ("libm.so", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s\n", dlerror());
exit(1);
}
dlerror(); /* Clear any existing error */
*(void **) (&cosine) = dlsym(handle, "cos");
if ((error = dlerror()) != NULL) {
fprintf (stderr, "%s\n", error);
exit(1);
}
printf ("%f\n", (*cosine)(2.0));
dlclose(handle);
return 0;
}
If this program were in a file named "foo.c", you would build the program with the following command:
gcc -rdynamic -o foo foo.c -ldl
Libraries exporting _init() and _fini() will want to be compiled as follows, using bar.c as the example name:
gcc -shared -nostartfiles -o bar bar.c