Ubuntu16.04手工搭建emscripten编译环境

Ubuntu16.04手工搭建emscripten编译环境

官方手册:http://kripken.github.io/emscripten-site/docs/building_from_source/building_emscripten_from_source_on_linux.html#building-emscripten-on-linux


1     安装依赖项

sudo apt-get update

sudo apt-get install python2.7

sudo apt-get install nodejs

sudo apt-get install build-essential

sudo apt-get install cmake

sudo apt-get install git-core

sudo apt-get install default-jre

2     安装Fastcomp(LLVM+Clang)

官方文档:http://kripken.github.io/emscripten-site/docs/building_from_source/building_fastcomp_manually_from_source.html#building-fastcomp-from-source

2.1     下载fastcomp代码

mkdir –p /home/fzn

cd /home/fzn

git clone https://github.com/kripken/emscripten-fastcomp

cd emscripten-fastcomp

git clone https://github.com/kripken/emscripten-fastcomp-clang tools/clang

注意 emscripten-fastcomp-clang 的代码必须放在 emscripten-fastcomp/tools/clang/目录下。如无法使用git,下载代码包,解压重命名并按照上述的目录结构放置也可以。

2.2     编译代码

配置编译选项

cd /home/fzn/ emscripten-fastcomp

mkdir build

cd build

cmake .. -DCMAKE_BUILD_TYPE=Release \

-DLLVM_TARGETS_TO_BUILD="X86;JSBackend" \

-DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF \

-DCLANG_INCLUDE_TESTS=OFF

开始编译

make

备注:对于Linux,可以使用“cat /proc/cpuinfo | grep "^cpu cores" | uniq”查询cpu核心数。

然后根据查询结果,用“make –j2”、“make –j4” 或 “make –j8”等加快编译速度

3     安装emscripten

3.1     获取emscripten代码

cd /home/fzn

git clone https://github.com/kripken/emscripten.git

clone完毕后,/home/fzn下多了一个emscripten目录,里面存储着emscripten项目代码。

3.2     修改配置文件

官方文档:http://kripken.github.io/emscripten-site/docs/building_from_source/configuring_emscripten_settings.html#configuring-emscripten-settings

cd /home/fzn/emscripten

./emcc --help

第一次运行emcc,会加载欢迎界面,并自动生成配置文件~/.emscripten

root@RH2288H-V3:/home/fzn/emscripten# ./emcc --help

 

==============================================================================

Welcome to Emscripten!

 

This is the first time any of the Emscripten tools has been run.

 

A settings file has been copied to ~/.emscripten, at absolute path: /root/.emscr                                                                                               ipten

 

It contains our best guesses for the important paths, which are:

 

  LLVM_ROOT       = /usr/bin

  NODE_JS         = /usr/bin/nodejs

  EMSCRIPTEN_ROOT = /home/fzn/emscripten

 

Please edit the file if any of those are incorrect.

 

This command will now exit. When you are done editing those paths, re-run it.

==============================================================================

我们需要根据自己的安装位置修改配置文件,这里只需要修改LLVM_ROOT,将其修改为如下值。

 LLVM_ROOT =os.path.expanduser(os.getenv('LLVM', '/home/fzn/emscripten-fastcomp/build/bin'))

4     验证安装

4.1     基本测试

尝试编译emscripten源代码中提供的测试用例hello_world.cpp,发现其报错!

root@RH2288H-V3:/home/fzn/emscripten# ./emcc tests/hello_world.cpp

WARNING:root:retrieving port: binaryen from https://github.com/WebAssembly/binar                                                                                               yen/archive/version_48.zip

ERROR:root:a problem occurred when using an emscripten-ports library. try to run                                                                                                   emcc --clear-ports    and then run this command again

Traceback (most recent call last):

  …

  …

  urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate ve                                                                                               rify failed (_ssl.c:590)>

4.2     解决问题

这里出现这个问题,是因为笔者使用的服务器联网时认证出错。

根据错误中的地址自行下载相关文件。

https://github.com/WebAssembly/binaryen/archive/version_48.zip

然后将其放到/home/fzn目录下

unzip version_48.zip

(将解压得到的文件夹重命名为binaryen)

修改配置文件~/.emscripten,只需要修改BINARYEN_ROOT,将其值修改为:

BINARYEN_ROOT = os.path.expanduser(os.getenv('BINARYEN', '/home/fzn/binaryen'))

4.3     最终测试

重新运行基本测试用例

root@RH2288H-V3:/home/fzn/emscripten# ./emcc tests/hello_world.cpp

目录下生成”a.out.js”说明编译成功。

官方手册:http://kripken.github.io/emscripten-site/docs/building_from_source/verify_emscripten_environment.html#verifying-the-emscripten-environment

当然也可以做更全面的测试

cd /home/fzn/emscripten

python tests/runner.py

此处运行时间较长,因测试用例较多,可能有部分测试用例不通过,但不影响使用

 


  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值