Up and running ASM.js in browser
-
Install Emscripten SDK
Download Emscripten SDK Offline Installer and install it. For more information about installation process refer https://kripken.github.io/emscripten-site/docs/getting_started/index.html
-
Check Emscripten installation
Click on Windows -> Search and search for Emscripten Command Prompt. Check Emscripten version.
emcc -v
emcc is transcompiler to compile C/C++ code to javascript code.
-
Create C/C++ test file
mkdir asmdemo
cd asmdemo
copy NUL hello-world.c (create hello-world.c)
Copy following content into newly created hello-world.c
#include<stdio.h>
int main() {
printf("hello, world!\n");
return 0;
}
-
Compile C/C++ code using emcc
emcc hello-world.c
it will create file name a.out.js
-
Run
node a.out.js
-
ASM.js in Browser
- We want HTML so that we can view it in the browser. Enter this command to specify and HTML document.
emcc hello-world.c -o hello.html
- Open hello.html that with your browser, and you can see it as a web page.
Written on July 10, 2016