lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <dlfcn.h> |
| 2 | #include <error.h> |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | |
| 6 | int |
| 7 | main (void) |
| 8 | { |
| 9 | void *h; |
| 10 | int (*fp) (int); |
| 11 | int res; |
| 12 | |
| 13 | h = dlopen ("${ORIGIN}/testobj1.so", RTLD_LAZY); |
| 14 | if (h == NULL) |
| 15 | error (EXIT_FAILURE, 0, "while loading `%s': %s", "testobj1.so", |
| 16 | dlerror ()); |
| 17 | |
| 18 | fp = dlsym (h, "obj1func1"); |
| 19 | if (fp == NULL) |
| 20 | error (EXIT_FAILURE, 0, "getting `obj1func1' in `%s': %s", |
| 21 | "testobj1.so", dlerror ()); |
| 22 | |
| 23 | res = fp (10); |
| 24 | printf ("fp(10) = %d\n", res); |
| 25 | |
| 26 | if (dlclose (h) != 0) |
| 27 | error (EXIT_FAILURE, 0, "while close `%s': %s", |
| 28 | "testobj1.so", dlerror ()); |
| 29 | |
| 30 | return res != 42; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | extern int foo (int a); |
| 35 | int |
| 36 | foo (int a) |
| 37 | { |
| 38 | return a + 10; |
| 39 | } |