dlttest.c 794 B

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