官网安装 emsdk 的方法比较慢,可以直接安装 emscripten brew install emscripten.
安装完底部有提示需要修改手动修改 ~/.emscripten.
将
LLVM_ROOT = os.path.expanduser(os.getenv('LLVM') or '/usr/bin') # directory
BINARYEN_ROOT = os.path.expanduser(os.getenv('BINARYEN') or '') # directory
修改成
LLVM_ROOT = os.path.expanduser(os.getenv('LLVM') or '/usr/local/opt/emscripten/libexec/llvm/bin') # directory
#BINARYEN_ROOT = os.path.expanduser(os.getenv('BINARYEN') or '') # directory
再运行 emcc -v
在编译过程中,如 emcc hello.c -s WASM=1 -o hello.html,可能会报 OSError: [Errno 2] No such file or directory 的错误,安装 brew install cmake 搞定!