提问人:si yan 提问时间:7/16/2021 更新时间:7/21/2021 访问量:1692
导入“wasi_snapshot_preview1”时出现 Wasmer 错误。proc_exit“:未知导入。预期功能
Wasmer Error while importing "wasi_snapshot_preview1"."proc_exit": unknown import. Expected Function
问:
我使用 Clang 编译以下 C 文件,
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int length(char* s) {
return strlen(s);
}
int matrix(int row, int col) {
printf("this is matrix\n");
int a[row][col];
int b[col][row];
int r[row][row];
for(int i = 0; i<row; i++) {
for(int j = 0; j<col; j++) {
a[i][j] = rand()%1000+1;
b[j][i] = rand()%1000+1;
}
}
for(int i = 0; i<row; i++) {
for(int j = 0; j<row; j++) {
r[i][j] = 0;
for(int k = 0; k<col; k++) {
r[i][j] += a[i][k] * b[k][j];
}
}
}
return r[row-1][row-1];
}
int main(){
int a = matrix(10, 12);
printf("a: %d\n", a);
printf("length: %d\n", length("abcd"));
return 0;
}
我的编译命令如下,
clang --sysroot home/user/wasi-sdk-12.0/share/wasi-sysroot/ \
-Wl,--export-all \
-o matrix.wasm matrix.c
我使用 wasm2wat 将 wasm 文件翻译成 wat 格式。文件内容如下导入,
(import "wasi_snapshot_preview1" "proc_exit" (func $__wasi_proc_exit (type 2)))
(import "wasi_snapshot_preview1" "fd_seek" (func $__wasi_fd_seek (type 3)))
(import "wasi_snapshot_preview1" "fd_write" (func $__wasi_fd_write (type 4)))
(import "wasi_snapshot_preview1" "fd_close" (func $__wasi_fd_close (type 5)))
(import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__wasi_fd_fdstat_get (type 6)))
我使用 wasmer 运行 webassembly 文件,
wasmer run matrix.wasm --invoke matrix 10 12
然后出现错误,
error: failed to run `matrix.wasm`
╰─> 1: Error while importing "wasi_snapshot_preview1"."proc_exit": unknown import. Expected Function(FunctionType { params: [I32], results: [] })
我可以成功运行它
wasmer matrix.wasm
我不知道如何使用这些导入行正确调用特定的导出函数。当我删除它们时,程序运行良好。但是,由于我删除了fd_write行,因此它不会打印任何内容。我怎样才能成功地执行这个程序
wasmer matrix.wasm --invoke matrix 10 12
答: 暂无答案
评论