1.3 Emscripten SDK

Emscripten is a compiler that compiles C/C++ to WebAssembly (WASM).


What is Emscripten?

Emscripten translates:

  • C/C++ code → WebAssembly
  • System APIs → JavaScript equivalents
  • OpenGL → WebGL

Why do we need Emscripten?

For the WASM build of OpenSSL that runs in Blazor WebAssembly.


Prerequisites


Installation in WSL

Step 1: Open WSL

wsl

Step 2: Clone Emscripten SDK

# To the opt directory (system-wide)
cd /opt
 
# Clone as root
sudo git clone https://github.com/emscripten-core/emsdk.git
sudo chown -R $USER:$USER /opt/emsdk

Or in home directory (only for your user):

git clone https://github.com/emscripten-core/emsdk.git ~/emsdk
cd ~/emsdk

Step 3: Install latest version

cd /opt/emsdk   # or ~/emsdk
 
# Install latest stable version
./emsdk install latest
 
# Activate
./emsdk activate latest

Step 4: Set environment variables

Temporary (this session only):

source /opt/emsdk/emsdk_env.sh

Permanent (in .bashrc):

echo 'source /opt/emsdk/emsdk_env.sh' >> ~/.bashrc

Verification

# Emscripten Compiler
emcc --version

Expected output:

emcc (Emscripten gcc/clang-like replacement) 3.1.xx
# Additional tools
emar --version
emranlib --version

Quick Test

Create a test file:

cat > hello.c << 'EOF'
#include <stdio.h>
 
int main() {
    printf("Hello from WebAssembly!\n");
    return 0;
}
EOF

Compile to WASM:

emcc hello.c -o hello.js
 
# Run with Node.js
node hello.js
# Output: Hello from WebAssembly!

For OpenSSL Build

For the WASM build of OpenSSL, these Emscripten tools are used:

Tool Usage
————-
emcc C compiler (replaces gcc)
emar Archiver (replaces ar)
emranlib Ranlib (replaces ranlib)
emconfigure Wrapper for ./Configure
emmake Wrapper for make

Example:

# Instead of:
./Configure linux-x86_64
make
 
# With Emscripten:
emconfigure ./Configure linux-generic32
emmake make

Update Version

cd /opt/emsdk   # or ~/emsdk
 
# Fetch updates
git pull
 
# Install latest version
./emsdk install latest
./emsdk activate latest
 
# Reload environment
source ./emsdk_env.sh

Common Problems

"emcc: command not found"

Environment not loaded:

source /opt/emsdk/emsdk_env.sh

"Python not found"

Emscripten needs Python 3:

# Ubuntu
sudo apt install python3
 
# Fedora
sudo dnf install python3

Old version activated

# Check active version
emcc --version
 
# If outdated, reactivate
cd /opt/emsdk
./emsdk activate latest
source ./emsdk_env.sh

Continue to


Wolfgang van der Stille @ EMSR DATA d.o.o. - Post-Quantum Cryptography Professional

Zuletzt geändert: on 2026/01/29 at 09:16 PM