webassembly - Uncaught (in promise) LinkError: WebAssembly Instantiation: Import #1 module="env" function="__memory_base" error: global import must be a number
问题描述
I am following the Google CodeLab An Introduction to Web Assembly to learn WebAssembly.
When I work on the step of Serve over HTTP, I hit the below error:
Uncaught (in promise) LinkError: WebAssembly Instantiation: Import #1 module="env" function="__memory_base" error: global import must be a number or WebAssembly.Global object
at createWebAssembly (http://127.0.0.1:8000/:11:57)
at async init (http://127.0.0.1:8000/:46:18)
Here is the JavaScript running on the webpage:
async function createWebAssembly(path, importObject) {
const result = await window.fetch(path);
const bytes = await result.arrayBuffer();
return WebAssembly.instantiate(bytes, importObject);
}
const memory = new WebAssembly.Memory({initial: 256, maximum: 256});
let exports = null;
async function init() {
const env = {
'abortStackOverflow': _ => { throw new Error('overflow'); },
'table': new WebAssembly.Table({initial: 0, maximum: 0, element: 'anyfunc'}),
'tableBase': 0,
'memory': memory,
'memoryBase': 1024,
'STACKTOP': 0,
'STACK_MAX': memory.buffer.byteLength,
};
const importObject = {env};
const wasm = await createWebAssembly('output.wasm', importObject);
exports = wasm.instance.exports;
console.info('got exports', exports);
exports._board_init(); // setup lyff board
// TODO: interact with lyff board
}
init();
The error is from WebAssembly.instantiate(bytes, importObject)
; however, I cannot step into that function though. Can someone please let me know what I am missing? Thank you in advance!
解决方案
I had the same issue and found the solution on GitHub:
https://github.com/googlecodelabs/web-assembly-introduction/issues/11
With later version of emcc replace
memoryBase
with__memory_base
andtableBase
with__table_base
.
推荐阅读
- active-directory - 从 VB.Net 中的 ActiveDirectory 中检索 SAMAccountName
- javascript - 停止 dom 中的 href 事件并继续 DOM 事件?
- java - 什么时候迭代器应该在源修改后抛出异常?
- mysql-workbench - 在 MySQL Workbench 中扩展代码片段
- sql-server - DECIMAL 16 位精度
- c# - 在 Web 应用程序中选择一个文件夹
- symfony - React Native Axios 发布请求在本地主机上不起作用
- c++ - 如何在 VS Code 中创建 C++ 项目并链接 main、functions 和 header?
- asynchronous - 从 NETCore Windows 服务异步调用非静态方法
- java - 如何在 Windows 10 上的 Android Studio 上实现 Nao 机器人 V3 和 Android 应用程序之间的通信?