← 返回命令列表

Linux command

emcc 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Compile C to WebAssembly

emcc [input.c] -o [output.wasm]

Compile to JavaScript

emcc [input.c] -o [output.js]

Compile with HTML harness

emcc [input.c] -o [output.html]

Compile C++

em++ [input.cpp] -o [output.js]

Optimize for size

emcc -Os [input.c] -o [output.wasm]

Optimize for speed

emcc -O3 [input.c] -o [output.wasm]

Export specific functions

emcc -sEXPORTED_FUNCTIONS=['_main','_myFunc'] [input.c] -o [output.js]

说明

emcc (Emscripten Compiler Frontend) compiles C and C++ code to WebAssembly (Wasm) or JavaScript using LLVM and Emscripten. It enables running native code in web browsers and other Wasm runtimes. Emscripten provides a compatibility layer for POSIX APIs, OpenGL (via WebGL), and SDL. It can compile entire codebases including games and applications to run in browsers.

参数

-o _file_
Output file (.js, .wasm, .html).
-O0 to -O3, -Os, -Oz
Optimization levels.
-s _SETTING=VALUE_
Emscripten-specific settings.
-I _dir_
Include directory.
-L _dir_
Library directory.
-l _lib_
Link library.
-g
Generate debug information.
--preload-file _path_
Preload file into virtual filesystem.
--embed-file _path_
Embed file in output.
-sMODULARIZE
Output as ES6 module.

FAQ

What is the emcc command used for?

emcc (Emscripten Compiler Frontend) compiles C and C++ code to WebAssembly (Wasm) or JavaScript using LLVM and Emscripten. It enables running native code in web browsers and other Wasm runtimes. Emscripten provides a compatibility layer for POSIX APIs, OpenGL (via WebGL), and SDL. It can compile entire codebases including games and applications to run in browsers.

How do I run a basic emcc example?

Run `emcc [input.c] -o [output.wasm]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o _file_ do in emcc?

Output file (.js, .wasm, .html).