| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <dlfcn.h> | 
|  | 2 | #include <stdio.h> | 
|  | 3 | #include <stdlib.h> | 
|  | 4 |  | 
|  | 5 | extern int call_me (void); | 
|  | 6 |  | 
|  | 7 | int | 
|  | 8 | call_me (void) | 
|  | 9 | { | 
|  | 10 | void *h; | 
|  | 11 | int (*fp) (void); | 
|  | 12 | int res; | 
|  | 13 |  | 
|  | 14 | h = dlopen ("reldepmod1.so", RTLD_LAZY); | 
|  | 15 | if (h == NULL) | 
|  | 16 | { | 
|  | 17 | printf ("cannot open reldepmod1.so in %s: %s\n", __FILE__, dlerror ()); | 
|  | 18 | exit (1); | 
|  | 19 | } | 
|  | 20 |  | 
|  | 21 | fp = dlsym (h, "foo"); | 
|  | 22 | if (fp == NULL) | 
|  | 23 | { | 
|  | 24 | printf ("cannot get address of foo in global scope: %s\n", dlerror ()); | 
|  | 25 | exit (1); | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | res = fp () - 42; | 
|  | 29 |  | 
|  | 30 | if (dlclose (h) != 0) | 
|  | 31 | { | 
|  | 32 | printf ("failure when closing h in %s: %s\n", __FILE__, dlerror ()); | 
|  | 33 | exit (1); | 
|  | 34 | } | 
|  | 35 |  | 
|  | 36 | return res; | 
|  | 37 | } |