test_dlc.c 725 B

1234567891011121314151617181920212223242526272829303132
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "tool.h"
  4. int main() {
  5. atexit(dlcExit);
  6. DlcHandle *dlc = openLibary(LIB_TEST1, RTLD_NOW); // TEST_LIB_PATH 传进来的分隔符 都是 "/"
  7. if (dlc == NULL) {
  8. fprintf(stderr, "libary not found!\n");
  9. exit(EXIT_FAILURE);
  10. }
  11. typedef int func(int a);
  12. NEW_DLC_SYMBOL(int, INT);
  13. NEW_DLC_SYMBOL(func, FUNC);
  14. DLC_SYMBOL(INT) a;
  15. DLC_SYMBOL(FUNC) fun;
  16. a = READ_SYMBOL(dlc, "num", INT);
  17. fun = READ_SYMBOL(dlc, "test", FUNC);
  18. printf("a = %d, test = %d\n", GET_SYMBOL(a), GET_SYMBOL(fun)(GET_SYMBOL(a)));
  19. FREE_SYMBOL(a);
  20. FREE_SYMBOL(fun);
  21. if (!freeLibary(dlc))
  22. exit(EXIT_FAILURE);
  23. return 0;
  24. }