Skip to main content
In this tutorial, you’ll learn how to compile and execute a basic C program directly in your browser using WebAssembly. By following these steps, you can seamlessly port native C code to the web.

1. Create the C Source File

  1. Open your project folder (e.g., WASM) in Visual Studio Code.
  2. Create a file named hello.c with the following content:

2. Compile to WebAssembly

In the integrated terminal, run:
This command produces three output files: Verify the files:
Ignore any cache:INFO messages during compilation—they’re just Emscripten diagnostics.

3. Run in the Browser

Serve the folder with a static server (for example, Live Server in VS Code) and open hello.html. You should see:

4. Explore the Generated Loader

Open hello.html to inspect how it integrates the loader:
Next, examine the key loader function in hello.js:
The image shows a code editor with JavaScript code open, specifically focusing on WebAssembly (WASM) file handling. The editor displays syntax highlighting and a file explorer on the left.
This snippet demonstrates how the .wasm binary is fetched and instantiated, completing the path from C source to browser execution.

References

Watch Video

Practice Lab