Skip to content

Instantly share code, notes, and snippets.

View kyorohiro's full-sized avatar
⚔️
Busy

Kiyohiro Kawamura kyorohiro

⚔️
Busy
View GitHub Profile
@kyorohiro
kyorohiro / helloworld.c
Created December 28, 2017 16:29
Hello World Test
#include<stdio.h>
int main() {
printf("Hello, World!!");
}
$emacs main.c
$emcc main.c
include<stdio.h>
int main() {
printf("Hello World!!");
return 0;
}
$mv a.out.js a.out.js.backup
$emcc main.c -s NO_EXIT_RUNTIME=0 -s WASM=1
$ls -al
total 872
drwxr-xr-x 7 kyorohiro staff 238 12 29 00:41 .
drwxr-xr-x 3 kyorohiro staff 102 12 29 00:25 ..
-rw-r--r-- 1 kyorohiro staff 98265 12 29 00:41 a.out.js
-rw-r--r-- 1 kyorohiro staff 294319 12 29 00:41 a.out.js.backup
-rw-r--r-- 1 kyorohiro staff 44476 12 29 00:41 a.out.wasm
-rw-r--r-- 1 kyorohiro staff 73 12 29 00:30 main.c
$ emcc main.c -o hello.html -O2 -s WASM=1
$ ls -al
total 1000
drwxr-xr-x 10 kyorohiro staff 340 12 29 21:49 .
drwxr-xr-x 4 kyorohiro staff 136 12 29 21:39 ..
-rw-r--r-- 1 kyorohiro staff 31908 12 29 00:48 a.out.js
-rw-r--r-- 1 kyorohiro staff 294319 12 29 00:41 a.out.js.backup
-rw-r--r-- 1 kyorohiro staff 24157 12 29 00:48 a.out.wasm
-rw-r--r-- 1 kyorohiro staff 102727 12 29 21:49 hello.html
-rw-r--r-- 1 kyorohiro staff 31598 12 29 21:49 hello.js
$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
#include<stdio.h>
int main() {
printf("Hello World!!\r\n");
return 0;
}
$ emcc libsqrt.c
#include <math.h>
int int_sqrt(int x) {
return sqrt(x);
}
$ emacs main.c
#include<stdio.h>
$ emcc libsqrt.c -o libsqrt.html -s EXPORTED_FUNCTIONS='["_int_sqrt"]' -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]'
$ emacs main.html
<html>
<head>
<title>Test</title>
</head>
<body>
<script src="libsqrt.js"></script>
<div id="test"></div>
<script>
$emacs libtest.c
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
//
// int
int int_sqrt(int x) {
$ emacs libtest1.c
void add01(int i, char output[]) {
output[0] = i+i;
}
void add02(int i, char* output) {
output[0] = i+i;
}