Running Hello World with Emscripten in Node.js
In this section, we will see how to convert C/C++ code into the WebAssembly binary via Emscripten and run it along with Node.js.
Note
If the terminal errors out with emcc command not found, your terminal environment might have been reset. To set up the environment, run the following command from inside the emsdk
folder:
source ./emsdk_env.sh
Let's follow the tradition of Brian Kernighan, by writing "Hello, world" with a slight twist. Let's do a "Hello, Web":
- First, we create a
hello_web.c
file:$ touch hello_web.c
- Launch your favorite editor and add the following code:
#include <stdio.h> int main() { printf("Hello, Web!\n"); return 0; }
It is a simple C program with a main
function. The main
function is the entry point during the runtime. When this code is compiled and executed using Clang (clang sum.c &...