$mkdir example // make folder
$cd example // enter example folder
$nano example.c //make c example file
#include <stdio.h>
int main(int argc, char ** argv) {
printf("github by kyu\n"); //waring Have to put '\n'. if not, can make error
return 0;
}
$emcc example.c -s WASM=1 -o example.html
$cd emsdk
$./emsdk activate --build=Release sdk-incoming-64bit binaryen-master-64bit
$source ./emsdk_env.sh --build=Release
$emcc example.c -s WASM=1 -o example.html
->If want to include some files(ex, txt or img etc.), you need to use other command line
emcc can not access to files on disks. You just have block of memory. WASM code could be called from JS and also WASM could call JS function.
So, if want to include some files use under command line without above.
$emcc example.c -s WASM=1 -o example.html --preload-file /Users/kyu/Desktop/WebAssembly/emsdk/WebTest/
$emrun --no_browser example.html --port 8080 //the browser will run 6931 port. 8080 extends to 6931.
Once the HTTP server is running, you can access http://localhost:6931/example.html this link.
If you see 'github by kyu' on console, you are success complie Web Assembly!
$npm install http-server -g
$http-server /Users/kyu/Desktop/WebAssembly/emsdk/WebTest -o
Once the HTTP server is running, you can access http://localhost:8080/example.html this link.