我正在尝试一个简单的示例来调用C编译为JavaScript的.wasm函数。“声明失败:您需要等待运行时准备就绪”在JavaScript中调用C函数时出错
这是counter.c
文件:
#include <emscripten.h>
int counter = 100;
EMSCRIPTEN_KEEPALIVE
int count() {
counter += 1;
return counter;
}
我把它用emcc counter.c -s WASM=1 -o counter.js
编译。
我main.js
JavaScript文件:
const count = Module.cwrap('count ', 'number');
console.log(count());
我index.html
文件只加载无论在身体,没有别的.js文件:
<script type="text/javascript" src="counter.js"></script>
<script type="text/javascript" src="main.js"></script>
我得到的错误是:
Uncaught abort("Assertion failed: you need to wait for the runtime to be ready (e.g. wait for main() to be called)") at Error
当我tr y致电count()
,电话号码main.js
。 如何等待运行时准备就绪?