我正在嘗試一個簡單的示例來調用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
。 如何等待運行時準備就緒?