dltest.c 631 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <fcntl.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <dlfcn.h>
  5. extern void _dlinfo();
  6. int main(int argc, char **argv) {
  7. void *handle;
  8. int (*myhowdy)(const char *s);
  9. char *error;
  10. #ifdef __UCLIBC__
  11. _dlinfo(); /* not supported by ld.so.2 */
  12. #endif
  13. handle = dlopen ("./libhowdy.so", RTLD_LAZY);
  14. if (!handle) {
  15. fputs (dlerror(), stderr);
  16. exit(1);
  17. }
  18. myhowdy = dlsym(handle, "howdy");
  19. if ((error = dlerror()) != NULL) {
  20. fputs(error, stderr);
  21. exit(1);
  22. }
  23. myhowdy("hello world!\n");
  24. #ifdef __UCLIBC__
  25. _dlinfo(); /* not supported by ld.so.2 */
  26. #endif
  27. dlclose(handle);
  28. return EXIT_SUCCESS;
  29. }