LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

emcc

compile C/C++ to WebAssembly or JavaScript

TLDR

Compile C to WebAssembly
$ emcc [input.c] -o [output.wasm]
copy
Compile to JavaScript
$ emcc [input.c] -o [output.js]
copy
Compile with HTML harness
$ emcc [input.c] -o [output.html]
copy
Compile C++
$ em++ [input.cpp] -o [output.js]
copy
Optimize for size
$ emcc -Os [input.c] -o [output.wasm]
copy
Optimize for speed
$ emcc -O3 [input.c] -o [output.wasm]
copy
Export specific functions
$ emcc -sEXPORTED_FUNCTIONS=['_main','_myFunc'] [input.c] -o [output.js]
copy

SYNOPSIS

emcc [options] files

DESCRIPTION

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.

PARAMETERS

-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.

CONFIGURATION

.emscripten

Emscripten configuration file containing SDK paths and compiler settings.

CAVEATS

Not all C/C++ features work identically. File system access requires virtual filesystem. Threading needs SharedArrayBuffer. Performance differs from native. Large applications may have long compile times. Browser security restrictions apply.

HISTORY

Emscripten was created by Alon Zakai at Mozilla in 2011, initially targeting asm.js before WebAssembly existed. When WebAssembly launched in 2017, Emscripten became the primary compiler toolchain for bringing C/C++ to the web.

SEE ALSO

clang(1), wasm2wat(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid