Hello WebAssembly

152 阅读1分钟

Hello WebAssembly

本文运行一下Hello WebAssembly

安装

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh

编译运行hello.js

新打开一个命令行终端一定要

source ./emsdk_env.sh
// hello.c
#include <stdio.h>

int main() {
  printf("hello, world!\n");
  return 0;
}
emcc hello.c -o hello.js

可以看到会新生成一个hello.wasm和hello.js

node hello.js

编译运行hello.html

emcc hello.c -O3 -o hello.html
python -m SimpleHTTPServer 8000

Reference

wasmbyexample.dev/examples/he…