dylib.h 967 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the License); you may
  5. * not use this file except in compliance with the License.
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. */
  9. #ifndef GMSSL_DYLIB_H
  10. #define GMSSL_DYLIB_H
  11. #include <string.h>
  12. #include <stdint.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #ifdef WIN32
  17. #include <windows.h>
  18. typedef HMODULE dylib_handle_t;
  19. #define dylib_load_library(so_path) LoadLibraryA(so_path)
  20. #define dylib_get_function(handle,name) GetProcAddress(handle,name)
  21. #define dylib_close_library(handle)
  22. #define dylib_error_str() ""
  23. #else
  24. #include <dlfcn.h>
  25. typedef void *dylib_handle_t;
  26. #define dylib_load_library(so_path) dlopen(so_path,RTLD_LAZY)
  27. #define dylib_get_function(handle,name) dlsym(handle,name)
  28. #define dylib_close_library(handle) dlclose(handle)
  29. #define dylib_error_str() dlerror()
  30. #endif
  31. #ifdef __cplusplus
  32. }
  33. #endif
  34. #endif