test1.c 603 B

123456789101112131415161718192021222324252627282930313233
  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 ("./libtest1.so", RTLD_LAZY);
  13. if (!handle) {
  14. fprintf(stderr, "Could not open ./libtest1.so: %s\n", dlerror());
  15. exit(1);
  16. }
  17. mydltest = dlsym(handle, "dltest");
  18. if ((error = dlerror()) != NULL) {
  19. fprintf(stderr, "Could not locate symbol 'dltest': %s\n", error);
  20. exit(1);
  21. }
  22. mydltest("hello world!");
  23. dlclose(handle);
  24. return EXIT_SUCCESS;
  25. }