tool-dlc.cpp 849 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include "aFuntool.h"
  4. int test_func() {
  5. return 100;
  6. }
  7. int main(int argc, char **argv) {
  8. atexit(aFuntool::DlcHandle::dlcExit);
  9. if (argc != 2)
  10. return EXIT_FAILURE;
  11. char *lib = argv[1];
  12. aFuntool::DlcHandle dlc {lib, RTLD_NOW}; // TEST_LIB_PATH 传进来的分隔符 都是 "/"
  13. if (dlc.isOpen()) {
  14. fprintf(stderr, "libary not found!\n");
  15. return EXIT_FAILURE;
  16. }
  17. typedef int (func)(int a);
  18. typedef int (test)();
  19. auto a = dlc.getSymbol<int>("num");
  20. auto fun = dlc.getSymbol<func>("test");
  21. auto test_fun = aFuntool::DlcSymbol<test>(test_func, nullptr);
  22. int test_func_result = test_fun.getSymbol()();
  23. printf("a = %d, test = %d\n", *(a.getSymbol()), fun.getSymbol()(test_func_result));
  24. dlc.close();
  25. return EXIT_SUCCESS;
  26. }