我正在尝试使用webassembly在Angular和im中实现c / c ++。
#include <stdio.h>
int func(int n){
return n+2;
}
int main(){
printf("Hello world!\n");
int res = func(5);
printf("func(5) = %d\n", res);
return 0;
}
执行以下命令后,将生成两个文件.js和.wasm
emcc program.c -o hello.js -s WASM = 1 -s EXTRA_EXPORTED_RUNTIME_METHODS ='[“ cwrap”]'
使用.html文件,结果很好
emcc program.c -o hello.html -s WASM = 1 python -m SimpleHTTPServer 8080
<script async type="text/javascript" src="../hello.js"></script>
<p>Open the console to see the result!</p>
<script type='text/javascript'>
var Module = {
preRun: [],
postRun: [],
print: (function() {
return function(text) {
console.log("eeeeee",text);
};
})(),
};
</script>