test2.c 749 B

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