Emscripten 是一个将 C/C++ 代码编译为 WebAssembly 的工具链,适用于浏览器端高性能开发。以下是安装步骤:

✅ 系统要求

  • 操作系统:Linux/macOS(Windows 需使用 WSL)
  • 依赖项
    • Python 3.x
    • Ninja 构建工具
    • LLVM/Clang(建议版本 14+)
    • Git

📦 安装步骤

  1. 安装依赖
    sudo apt-get install build-essential ninja-build python3 git
    
  2. 下载 Emscripten
    git clone https://github.com/emscripten-core/emscripten.git
    
  3. 进入目录并构建
    cd emscripten
    ./build.sh
    
  4. 添加环境变量
    export PATH="$PATH:$PWD/emscripten"
    

🌐 使用示例

emcc -o hello.html hello.c

该命令会将 hello.c 编译为浏览器可运行的 hello.html 文件。

📘 扩展阅读

如需深入了解 Emscripten 的高级用法,可参考:
https://emscripten.org/docs.html

emscripten_logo

📝 提示:安装完成后建议验证版本,使用 emcc --version 检查是否正常。