Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我运行的时候抱错为这个 怎么办啊 #2

Closed
YC19940619 opened this issue May 2, 2018 · 5 comments
Closed

我运行的时候抱错为这个 怎么办啊 #2

YC19940619 opened this issue May 2, 2018 · 5 comments

Comments

@YC19940619
Copy link

WebAssembly Instantiation: table import 0 is smaller than initial 4, got 0 at fetch.then.then.then.module

@ixqbar
Copy link

ixqbar commented Jun 20, 2018

emcc math.c -Os -s BINARYEN_ASYNC_COMPILATION=0 -s WASM=1 -s SIDE_MODULE=1 -o math.wasm

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,
        DYNAMICTOP_PTR: 0,
        tempDoublePtr: 0,
        ABORT: 0,
        memory: new WebAssembly.Memory({ initial: 256, maximum: 256 }),
        table: new WebAssembly.Table({ initial: 2, maximum: 8, element: 'anyfunc' }),
        abortStackOverflow: function (allocSize) { },
        nullFunc_X: function () { },
        abort: function () { }
      })
      return new WebAssembly.Instance(module, imports)
    })
}

loadWebAssembly('math.wasm').then(instance => {
    const square = instance.exports._square
    console.log('2^2 =', square(2))
    console.log('3^2 =', square(3))
    console.log('(2 + 5)^2 =', square(2 + 5))
})

@terepiim
Copy link

terepiim commented Jul 5, 2018

what @Jonnywang said is perfectly correct and some changes are needed accroding to your question. .Just like this:
table: new WebAssembly.Table({ initial: 4, maximum: 8, element: 'anyfunc' })

@jsOcean
Copy link

jsOcean commented Jun 24, 2019

我运行了你代码里面的wasm文件是正确的,但是我自己生成的wasm运行会报错,我使用的命令是
emcc math.c -Os -s WASM=1 -s SIDE_MODULE=1 -o math.wasm
我的环境是
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 1.38.36
clang version 6.0.1 (Cswircachegitchromium.googlesource.com-external-github.com-emscripten--core-emscripten--fastcomp--clang 98df4be387dde3e3918fa5bbb5fc43e1a0e1daac) (Cswircachegitchromium.googlesource.com-external-github.com-emscripten--core-emscripten--fastcomp 1b4148f39a69c7fc62edadd85e4122b68694dfb7) (emscripten 1.38.31 : 1.38.31)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\emsdk\fastcomp\fastcomp\bin
shared:INFO: (Emscripten: Running sanity checks)
求指点

@jsOcean
Copy link

jsOcean commented Jun 24, 2019

这是我的报错的信息(index):30 Uncaught (in promise) LinkError: WebAssembly.Instance(): Import #0 module="env" function="__memory_base" error: global import must be a number or WebAssembly.Global object

@Hanks10100
Copy link
Owner

Fixed by dad3d37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants