| 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 (file: "${ORIGIN}/testobj1.so" , RTLD_LAZY); |
| 14 | if (h == NULL) |
| 15 | error (EXIT_FAILURE, errnum: 0, format: "while loading `%s': %s" , "testobj1.so" , |
| 16 | dlerror ()); |
| 17 | |
| 18 | fp = dlsym (handle: h, name: "obj1func1" ); |
| 19 | if (fp == NULL) |
| 20 | error (EXIT_FAILURE, errnum: 0, format: "getting `obj1func1' in `%s': %s" , |
| 21 | "testobj1.so" , dlerror ()); |
| 22 | |
| 23 | res = fp (10); |
| 24 | printf (format: "fp(10) = %d\n" , res); |
| 25 | |
| 26 | if (dlclose (handle: h) != 0) |
| 27 | error (EXIT_FAILURE, errnum: 0, format: "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 | } |
| 40 | |