Windows下安装Emscripten教程

首先要安装Emscripten环境需要先安装python和git环境;python和git环境安装简单自行百度下。

安装完成python和git置好环境变量后就可以开始安装Emscripten了,首先需要将emsdk的git项目克隆到本地。

Emscripten SDK的git地址:https://github.com/emscripten-core/emsdk,自行下载;

也可以用cmd执行如下命令:

git clone https://github.com/juj/emsdk.git

当拷贝完成后使用cmd进入emsdk目录中:

cd emsdk

更新emsdk版本,因为使用是的是git所以运行时会提示使用"git pull":

emsdk update
git pull

更新完成后安装最新的emsdk,并配置全局的环境变量:

emsdk install --global latest

当安装完成配置好后执行激活:

emsdk activate latest

配置好激活后需要应用环境变量(该步操作需要每次打开新的cmd都需要执行或者在安装完成将D:\text\emsdk\upstream\emscripten配置到环境变量中就可以):

emsdk_env.bat

如上操作都完成的话可以使用以下方法验证是否安装成功

  • emcc -v 不会报错
  • emcc --clear-cache 不会报错
  • 在emsdk里面创建个hello目录里创建个hello.c
#include <stdio.h>
int main() {
printf("Hello, world!\n");
}

执行:

emcc hello.c -s WASM=1 -o hello.html 

会编出来三个文件

证明配置成功

执行

emrun --no_browser --port 8080 hello.html

成功后在浏览器中输入http://localhost:8080/hello.html就会在控制台看到输出的“Hello, world!”。

 

如果出现

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc8 in position 3: ordinal not in range(128)

UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 214: illegal multibyte sequence

类似错误可能是文件路径有中文建议安装在英文目录环境下

或者按照如下解决方法:

找到emsdk\upstream\emscripten\tools目录下的shared.py文件

找到该段代码

if hasattr(subprocess, "run"):
    ret = subprocess.run(cmd, check=check, input=input, *args, **kw)
    logger.debug(debug_text)
    return ret

  # Python 2 compatibility: Introduce Python 3 subprocess.run-like behavior
  if input is not None:
    kw['stdin'] = subprocess.PIPE
  proc = Popen(cmd, *args, **kw)
  stdout, stderr = proc.communicate(input)
  result = Py2CompletedProcess(cmd, proc.returncode, stdout, stderr)
  if check:
    result.check_returncode()

替换成:

  if hasattr(subprocess, 'run'):
    # Python 3.5 and above only
    kw.setdefault('encoding', 'utf-8')
    result = subprocess.run(cmd, check=check, input=input, *args, **kw)
  else:
    # Python 2 compatibility: Introduce Python 3 subprocess.run-like behavior
    if input is not None:
      kw['stdin'] = subprocess.PIPE
    proc = Popen(cmd, *args, **kw)
    stdout, stderr = proc.communicate(input)
    result = Py2CompletedProcess(cmd, proc.returncode, stdout, stderr)
    if check:
      result.check_returncode()

 

  • 11
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值