如何执行程序?

问题描述 投票:0回答:0

如何在 WASM 中

exec
?它给出错误
45
Operation not supported
)。是否有一些标志来启用
exec
callee.wasm
不是
exec
的正确文件吗?

terminal

> emcc callee.c -o callee.wasm
> emcc caller.c --embed-file callee.wasm -o index.html
> # will be used through index.html, but node is faster for development
> # note: MEMFS working directory is "/" and "/callee.wasm" exists
> # https://emscripten.org/docs/api_reference/Filesystem-API.html
> node index.js
Caller
Caller: 45

caller.c

#include <errno.h>
#include <stdio.h>
#include <unistd.h>

int main() {
  printf("Caller\n");

  char *args[] = {"./callee.wasm", NULL};
  execvp(args[0], args);

  printf("Caller: %d\n", errno);
}

callee.c

#include <stdio.h>

int main() {
  printf("Success!\n");
}

需要说明的是,这是简化版,所以不建议把

printf("Success!\n");
放在
caller.c
里,完全避免
exec

c webassembly emcc emsdk
© www.soinside.com 2019 - 2024. All rights reserved.