test_dlc.c 984 B

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