Emscripten Library Generator
raw JSON → 0.3.0 verified Fri May 01 auth: no javascript maintenance
The emscripten-library-generator (v0.3.0) converts normal JavaScript libraries into Emscripten's custom JS library format (.js) for use with the --js-library flag. It also auto-generates EXPORTED_FUNCTIONS lists via the --unresolved flag. Created by Emscripten author Evan Wallace, it resolves dependencies and prefixes symbols with underscores to match Emscripten's ABI. Development appears complete as of 2015; no recent releases. Unlike manual library authoring, it automates dependency resolution and underscore prefixing.
Common errors
error sh: emscripten-library-generator: command not found ↓
cause The tool is not installed globally or not in PATH.
fix
Run 'npm install -g emscripten-library-generator' and ensure npm global binaries are in PATH.
error Error: Cannot find module 'acorn' ↓
cause Missing dependency; old version of emscripten-library-generator may require acorn.
fix
Install acorn: 'npm install -g acorn' or install emscripten-library-generator locally and run via npx.
error SyntaxError: Unexpected token ... ↓
cause Input JavaScript uses ES6+ syntax not supported by the parser.
fix
Rewrite input files in ES5 syntax (no arrow functions, const/let, etc.).
Warnings
gotcha Top-level statements other than variable or function declarations are not supported. ↓
fix Put initialization code into a JavaScript function called as the first statement inside main() in C++.
gotcha All global symbols are automatically prefixed with an underscore to match Emscripten's output. ↓
fix In C++ code, use the underscore-prefixed names (e.g., _Foo_new) or use EXPORTED_FUNCTIONS with underscores.
gotcha The tool may not work with modern JavaScript features (ES6+). ↓
fix Use only ES5 syntax in input files.
Install
npm install emscripten-library-generator yarn add emscripten-library-generator pnpm add emscripten-library-generator Imports
- CLI tool
npm install -g emscripten-library-generator
Quickstart
npm install -g emscripten-library-generator
echo 'var counter = 0;
function increment() {
counter++;
return counter;
}
function increment_double() {
increment();
return counter * 2;
}' > input.js
emscripten-library-generator input.js > library.js
cat library.js