|
8 | 8 | #endif
|
9 | 9 | #include <stdlib.h>
|
10 | 10 | #include <string.h>
|
11 |
| -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) |
12 |
| -#include <dlfcn.h> |
13 |
| -#endif |
14 | 11 |
|
15 | 12 | #include "bh_platform.h"
|
16 | 13 | #include "bh_read_file.h"
|
17 | 14 | #include "wasm_export.h"
|
18 | 15 |
|
| 16 | +#if BH_HAS_DLFCN |
| 17 | +#include <dlfcn.h> |
| 18 | +#endif |
| 19 | + |
19 | 20 | static int app_argc;
|
20 | 21 | static char **app_argv;
|
21 | 22 |
|
@@ -47,7 +48,7 @@ print_help()
|
47 | 48 | printf(" for example:\n");
|
48 | 49 | printf(" --addr-pool=1.2.3.4/15,2.3.4.5/16\n");
|
49 | 50 | #endif
|
50 |
| -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) |
| 51 | +#if BH_HAS_DLFCN |
51 | 52 | printf(" --native-lib=<lib> Register native libraries to the WASM module, which\n");
|
52 | 53 | printf(" are shared object (.so) files, for example:\n");
|
53 | 54 | printf(" --native-lib=test1.so --native-lib=test2.so\n");
|
@@ -182,7 +183,7 @@ validate_env_str(char *env)
|
182 | 183 | }
|
183 | 184 | #endif
|
184 | 185 |
|
185 |
| -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) |
| 186 | +#if BH_HAS_DLFCN |
186 | 187 | typedef uint32 (*get_native_lib_func)(char **p_module_name,
|
187 | 188 | NativeSymbol **p_native_symbols);
|
188 | 189 |
|
@@ -232,7 +233,7 @@ load_and_register_native_libs(const char **native_lib_list,
|
232 | 233 |
|
233 | 234 | return native_handle_count;
|
234 | 235 | }
|
235 |
| -#endif /* end of defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) */ |
| 236 | +#endif /* BH_HAS_DLFCN */ |
236 | 237 |
|
237 | 238 | #if WASM_ENABLE_MULTI_MODULE != 0
|
238 | 239 | static char *
|
@@ -309,7 +310,7 @@ main(int argc, char *argv[])
|
309 | 310 | const char *addr_pool[8] = { NULL };
|
310 | 311 | uint32 addr_pool_size = 0;
|
311 | 312 | #endif
|
312 |
| -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) |
| 313 | +#if BH_HAS_DLFCN |
313 | 314 | const char *native_lib_list[8] = { NULL };
|
314 | 315 | uint32 native_lib_count = 0;
|
315 | 316 | void *native_handle_list[8] = { NULL };
|
@@ -403,7 +404,7 @@ main(int argc, char *argv[])
|
403 | 404 | }
|
404 | 405 | }
|
405 | 406 | #endif /* WASM_ENABLE_LIBC_WASI */
|
406 |
| -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) |
| 407 | +#if BH_HAS_DLFCN |
407 | 408 | else if (!strncmp(argv[0], "--native-lib=", 13)) {
|
408 | 409 | if (argv[0][13] == '\0')
|
409 | 410 | return print_help();
|
@@ -485,7 +486,7 @@ main(int argc, char *argv[])
|
485 | 486 | bh_log_set_verbose_level(log_verbose_level);
|
486 | 487 | #endif
|
487 | 488 |
|
488 |
| -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) |
| 489 | +#if BH_HAS_DLFCN |
489 | 490 | native_handle_count = load_and_register_native_libs(
|
490 | 491 | native_lib_list, native_lib_count, native_handle_list);
|
491 | 492 | #endif
|
@@ -564,7 +565,7 @@ main(int argc, char *argv[])
|
564 | 565 | os_munmap(wasm_file_buf, wasm_file_size);
|
565 | 566 |
|
566 | 567 | fail1:
|
567 |
| -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) |
| 568 | +#if BH_HAS_DLFCN |
568 | 569 | /* unload the native libraries */
|
569 | 570 | for (native_handle_idx = 0; native_handle_idx < native_handle_count;
|
570 | 571 | native_handle_idx++)
|
|
0 commit comments