Need to compile the C language demo program ADD.C
#include <stdio.h>
int add (int a,int b)
{
return a+b;
}
int main (void)
{
printf ("%d\n", add);
}
1, can be compiled with HTML output file, you can directly open the HTML file to see the effect
EMCC add.c-s Wasm=1-o add.html
Where-s wasm=1 must be added, otherwise the default generated file is not *.wasm but JS file
2, most of the situation is not recommended to output HTML files, directly generate wasm files and JS files. The generated JS file has the interface called webassembly, we just need to call the JS file interface.
EMCC add.c-s wasm=1-s Side_module=1-o add.js
3, if you want to write JS call webassembly, there are many ways, one of the following:
<script>
fetch (' add.wasm '). Then (res =
Res.arraybuffer ()
). Then (buf = {let
m_buf = new Uint8array (BUF);
Let API = Wasm.instantiatemodule (M_BUF);
Console.log ("123+1024=", Api.exports.add (123,1024));
});
</script>