Web Assembly C++ (1) : helloworld

环境部署

确保python版本至少是2.7以上的(ubuntu 18默认的是python3,理论上可以,我测试的也可以)
Emscripten SDK - emsdk

# Get the emsdk repo
git clone https://github.com/emscripten-core/emsdk.git

# Enter that directory
cd emsdk

# Download and install the VERSION SDK tools.
# 可以安装一个最新版,也可以指定版本,为了后续的维护,建议指定版本
#./emsdk install latest
./emsdk install 1.38.45

# Make the "latest" SDK "active" for the current user. (writes ~/.emscripten file)
./emsdk activate 1.38.45

# Activate PATH and other environment variables in the current terminal
source ./emsdk_env.sh

# Get a specific version using the upstream backend.
#./emsdk install latest-upstream

# Get a specific version using the fastcomp backend.
#./emsdk install 1.38.45-fastcomp

# Install CMake (optional, only needed for tests and building Binaryen)
sudo apt-get install cmake
sudo apt-get install python2.7
# Install Java (optional, only needed for Closure Compiler minification)
sudo apt-get install default-jre

Hello World

hello.c

#include <stdio.h>
int main(int argc, char ** argv) {
	printf("Hello, world!\n");
}
emcc hello.c -s WASM=1 -o hello.html

可能遇到的问题:
ModuleNotFoundError: No module named ‘distutils.spawn’
需要 python3-distutils

sudo apt-get install python3-distutils
emrun --no_browser --port 8080 .

或者使用python的

python -m http.server 8000

在这里插入图片描述

posted @ 2020-04-08 17:26  猫影  阅读(221)  评论(0)    收藏  举报