samples/native-lib: Add an example to use wamr API from native lib (#1649)
Real world native libs likely need to access the wasm_runtime_xxx API. This example demonstrates it. Build vmlib as a shared lib to make it straightforward to share a single runtime instance between iwasm and native libs.
This commit is contained in:
@ -49,14 +49,14 @@ will be generated.
|
||||
|
||||
```bash
|
||||
cd build
|
||||
./iwasm --native-lib=./libtest_add.so --native-lib=./libtest_sqrt.so --native-lib=./libtest_hello.so wasm-app/test.wasm
|
||||
./iwasm --native-lib=./libtest_add.so --native-lib=./libtest_sqrt.so --native-lib=./libtest_hello.so --native-lib=./libtest_hello2.so wasm-app/test.wasm
|
||||
```
|
||||
|
||||
### macOS
|
||||
|
||||
```bash
|
||||
cd build
|
||||
./iwasm --native-lib=libtest_add.dylib --native-lib=libtest_sqrt.dylib --native-lib=libtest_hello.dylib wasm-app/test.wasm
|
||||
./iwasm --native-lib=libtest_add.dylib --native-lib=libtest_sqrt.dylib --native-lib=libtest_hello.dylib --native-lib=libtest_hello2.dylib wasm-app/test.wasm
|
||||
```
|
||||
|
||||
The output is:
|
||||
@ -66,7 +66,11 @@ Hello World!
|
||||
10 + 20 = 30
|
||||
sqrt(10, 20) = 500
|
||||
test_hello("main", 0x0, 0) = 41
|
||||
malloc(42) = 0x24b8
|
||||
test_hello("main", 0x24b8, 42) = 41
|
||||
malloc(42) = 0x24e8
|
||||
test_hello("main", 0x24e8, 42) = 41
|
||||
Message from test_hello: Hello, main. This is test_hello_wrapper!
|
||||
test_hello2("main", 0x0, 0) = 85
|
||||
malloc(86) = 0x24e8
|
||||
test_hello2("main", 0x24e8, 86) = 85
|
||||
Message from test_hello2: Hello, main. This is test_hello2_wrapper! Your wasm_module_inst_t is 0x7fd443704990.
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user