Skip to main content

qjsc - QuickJS Compiler

The qjsc executable is the QuickJS JavaScript compiler. It compiles JavaScript source files into bytecode or C code that can be embedded in executables.

Basic Usage

Output Modes

qjsc can generate output in three different formats:
Generate C code with embedded bytecode:
This creates a C file containing bytecode as a byte array that can be compiled into your application.

Command-Line Options

Output Control

string
Set the output filename (default: out.c)
flag
Output raw bytecode instead of C code
flag
Output a complete C file with main() function and bytecode
The generated C file can be compiled directly into a standalone executable.

Code Generation

string
Set the C name of the generated data array
By default, the C name is derived from the filename.
string
Set the prefix for generated C names (default: qjsc_)
string
Set the script name as used in stack traces

Module Handling

flag
Compile as ES6 module (default=autodetect)
flag
Compile as classic JavaScript script (default=autodetect)
By default, qjsc automatically detects whether a file is a module based on:
  • File extension (.mjs files are modules)
  • Content analysis (presence of import/export statements)
string
Compile a dynamically loaded module or worker
string
Add initialization code for an external C module
This adds initialization code for C modules that will be linked with the executable.
flag
Do not add default system modules (std, os, bjson)
Useful for creating minimal executables without standard library dependencies.

Optimization

flag
Strip source code from the bytecode. Specify twice (-ss) to also strip debug info.
Stripping reduces bytecode size but makes debugging harder.
Stripping debug info will make stack traces less useful. Only use -ss for production builds where size is critical.

Runtime Configuration

string
Set the maximum stack size to N bytes (default: 262144)

Help

flag
Display help information and exit

Examples

Compile a Simple Script to C

The generated hello.c contains:

Create a Standalone Executable

Compile Multiple Files

All files will be compiled and embedded in the generated C code.

Compile with External C Module

Given a C module fib.c with an js_init_module_fib function:
In main.js:

Minimal Executable (No Standard Library)

This creates a smaller executable that doesn’t include the standard library.

Generate Optimized Bytecode

Compiling Modules

ES6 Module

Classic Script

Integration with Build Systems

Using with Make

Using with CMake

Generated C Code Structure

With -e flag (Standalone)

The generated C file includes:

Without -e flag (Library)

The generated C file includes only:
You can load this bytecode in your own application using JS_ReadObject().

Compiling Full C Applications

When using qjsc -e, you need to link against QuickJS and its dependencies:
The exact linker flags may vary depending on your system and QuickJS build configuration.

Common Use Cases

Embedding in Applications

Generate C code without main() to embed in your own application:
Then in your C code:

Pre-compiling for Faster Startup

Compile to bytecode and load at runtime:
Load in your application:

See Also