官方文档

https://www.wasm.com.cn/getting-started/developers-guide/
https://github.com/emscripten-core/emsdk

安装过程

yusen@yusenPC:~/wasm$ git clone https://github.com/juj/emsdk.git
正克隆到 'emsdk'...
remote: Enumerating objects: 2819, done.
remote: Counting objects: 100% (81/81), done.
remote: Compressing objects: 100% (46/46), done.
remote: Total 2819 (delta 48), reused 62 (delta 35), pack-reused 2738
接收对象中: 100% (2819/2819), 1.48 MiB | 566.00 KiB/s, 完成.
处理 delta 中: 100% (1802/1802), 完成.
yusen@yusenPC:~/wasm$ cd emsdk
yusen@yusenPC:~/wasm/emsdk$ ./emsdk install latest
Resolving SDK alias 'latest' to '2.0.26'
Resolving SDK version '2.0.26' to 'sdk-releases-upstream-823d37b15d1ab61bc9ac0665ceef6951d3703842-64bit'
Installing SDK 'sdk-releases-upstream-823d37b15d1ab61bc9ac0665ceef6951d3703842-64bit'..
Installing tool 'node-14.15.5-64bit'..
Downloading: /home/yusen/wasm/emsdk/zips/node-v14.15.5-linux-x64.tar.xz from https://storage.googleapis.com/webassembly/emscripten-releases-builds/deps/node-v14.15.5-linux-x64.tar.xz, 21391232 Bytes
Unpacking '/home/yusen/wasm/emsdk/zips/node-v14.15.5-linux-x64.tar.xz' to '/home/yusen/wasm/emsdk/node/14.15.5_64bit'
Done installing tool 'node-14.15.5-64bit'.
Installing tool 'releases-upstream-823d37b15d1ab61bc9ac0665ceef6951d3703842-64bit'..
Downloading: /home/yusen/wasm/emsdk/zips/823d37b15d1ab61bc9ac0665ceef6951d3703842-wasm-binaries.tbz2 from https://storage.googleapis.com/webassembly/emscripten-releases-builds/linux/823d37b15d1ab61bc9ac0665ceef6951d3703842/wasm-binaries.tbz2, 178006251 Bytes
Unpacking '/home/yusen/wasm/emsdk/zips/823d37b15d1ab61bc9ac0665ceef6951d3703842-wasm-binaries.tbz2' to '/home/yusen/wasm/emsdk/upstream'
Done installing tool 'releases-upstream-823d37b15d1ab61bc9ac0665ceef6951d3703842-64bit'.
Done installing SDK 'sdk-releases-upstream-823d37b15d1ab61bc9ac0665ceef6951d3703842-64bit'.
yusen@yusenPC:~/wasm/emsdk$ ./emsdk activate latest
Resolving SDK alias 'latest' to '2.0.26'
Resolving SDK version '2.0.26' to 'sdk-releases-upstream-823d37b15d1ab61bc9ac0665ceef6951d3703842-64bit'
Setting the following tools as active:
   node-14.15.5-64bit
   releases-upstream-823d37b15d1ab61bc9ac0665ceef6951d3703842-64bit

Next steps:
- To conveniently access emsdk tools from the command line,
  consider adding the following directories to your PATH:
    /home/yusen/wasm/emsdk
    /home/yusen/wasm/emsdk/node/14.15.5_64bit/bin
    /home/yusen/wasm/emsdk/upstream/emscripten
- This can be done for the current shell by running:
    source "/home/yusen/wasm/emsdk/emsdk_env.sh"
- Configure emsdk in your shell startup scripts by running:
    echo 'source "/home/yusen/wasm/emsdk/emsdk_env.sh"' >> $HOME/.bash_profile

测试demo

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

上面的走完了,打开浏览器就看到已经运行了。
打开console,运行_main()就可以看到又打印了hello world。
这样就实现了在js调用c函数。打算用这东西云顶工具。

最后修改:2021 年 07 月 27 日
如果觉得我的文章对你有用,请随意赞赏