(1)Emscripten环境搭建以及简单的使用方法介绍
简介:Emscripten可以把C/C++编译成.js和.wasm文件,用于浏览器使用。
①,安装Emscripten编译期
# Get the emsdk repo
git clone https://github.com/emscripten-core/emsdk.git
# Enter that directory
cd emsdk
git pull
# Download and install the latest SDK tools.
./emsdk install latest
# Make the "latest" SDK "active" for the current user. (writes .emscripten file)
./emsdk activate latest
# Activate PATH and other environment variables in the current terminal
source ./emsdk_env.sh
②,编写代码
hello.c
#include<stdio.h>
int main(){
printf(“hello world\n”);
}
编译:可以输出html,也k可以不进行输出。
./emcc hello.c -o hello.html

使用浏览器打开hello.html,结果如下,网页和控制台都能看到hello world。

参考
https://github.com/emscripten-core/emscripten
https://webassembly.org/
https://emscripten.org/
本文介绍如何使用Emscripten将C/C++代码编译成可在浏览器中运行的JavaScript和WebAssembly文件。通过详细步骤,从环境搭建到简单示例的编译,展示了Emscripten的基本用法。

1129

被折叠的 条评论
为什么被折叠?



