testscope.c 515 B

1234567891011121314151617181920212223242526272829
  1. #include <dlfcn.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #define LIBNAME "libA.so"
  5. int main(int argc, char **argv)
  6. {
  7. void *libA;
  8. void (*libAfn)(void);
  9. char *error;
  10. libA = dlopen(LIBNAME, RTLD_LAZY);
  11. if (!libA) {
  12. fprintf(stderr, "Could not open ./%s: %s\n", LIBNAME, dlerror());
  13. exit(1);
  14. }
  15. libAfn = dlsym(libA, "libA_func");
  16. if ((error = dlerror()) != NULL) {
  17. fprintf(stderr, "Could not locate symbol 'libA_func': %s\n", error);
  18. exit(1);
  19. }
  20. libAfn();
  21. dlclose(libA);
  22. return EXIT_SUCCESS;
  23. }