【发布时间】:2017-10-21 05:01:26
【问题描述】:
我最近开始使用 WebAssembly。我在尝试在我的 C 代码中使用登录时遇到了问题。我以最简单的方式重新创建了错误。我得到的错误是
Uncaught (in promise) LinkError: WebAssembly.Instance(): Import #1 module="env" function="_log" error: function import requires a callable
错误指向这个函数,具体是WebAsembly.Instance(module, imports)
function loadWebAssembly(filename, imports = {}) {
return fetch(filename)
.then((response) => response.arrayBuffer())
.then((buffer) => WebAssembly.compile(buffer))
.then((module) => {
imports.env = imports.env || {}
Object.assign(imports.env, {
memoryBase: 0,
tableBase: 0,
memory: new WebAssembly.Memory({
initial: 256,
maximum: 512,
}),
table: new WebAssembly.Table({
initial: 0,
maximum: 0,
element: 'anyfunc',
}),
})
return new WebAssembly.Instance(module, imports)
})
}
(我用loadWebAssembly('/test.wasm')调用这个函数)
我的 C 代码是
#include <math.h>
double test(v) {
return log(v)
}
编译时不会出错
emcc test.c -Os -s WASM=1 -s SIDE_MODULE=1 -o test.wasm
我一直无法修复这个错误,希望有人能帮助我。
【问题讨论】:
标签: javascript c webassembly