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
Uncaught WasmModule::Instantiate(): Import #0 module="env" function="abort" error: FFI is not an object #670
Comments
Those commands look ok. What is the error you see in the console? |
I am getting the same error. Latest emscripten, chrome canary. |
Oh, is the error you see in the console what's in the title? "Import #0 module="env" function="abort" error: FFI is not an object"? I missed it the first time I read this. Then the error is that the module is trying to import By default Instead, if you want to instantiate it yourself, you can look in the In theory a wasm file could be standalone, if you don't use any imports, manage your own stack, etc. and just provide exports that are called from outside. You can try to experiment with this using the |
Ah I see. Is there somewhere a standalone example or do I need to defiddle the |
We don't really have a good way to generate a standalone wasm file yet from C or C++. As I said, you can try Alternatively, if you're not using C or C++, then you can use binaryen directly to generate code, and then you can generate exactly what you want in terms of imports and exports and code. The mir2wasm project is doing that for Rust, for example. |
Is there actually some minimal |
What do you mean "work with asm.js and wasm"? |
It would be nice to have a minimal
|
And what do you mean by minimal? Something smaller than As explained above, we don't have a way to have a truly standalone wasm file, so something smaller than However, I am working on dynamic linking of wasm now, and that might be a route to get there. On the |
I'm using following command to compile
Getting .wasm file from it, but no .js file. What did I miss? |
Ok. I simply did not have to use
|
I made it work after reading some Google tutorial https://codelabs.developers.google.com/codelabs/web-assembly-intro/index.html?index=..%2F..%2Findex#3 // hello.c
#include <stdio.h>
float bezier1(float t, float p0, float p1) {
return (1 - t) * p0 + t * p1;
} emcc hello.c -s ONLY_MY_CODE=1 -s WASM=1 -s EXPORTED_FUNCTIONS="['_bezier1']" -o hello.js I didn't understand why I have to use underscore in function name and why I have to create a JS file. But it works. Finally, my JS code: const memory = new WebAssembly.Memory({ initial: 256, maximum: 256 });
const importObj = {
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,
}
};
fetch('hello.wasm').then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.instantiate(bytes, importObj))
.then((wa) => alert(wa.instance.exports._bezier1(0.5, 10, 20))); Overall I think there is so much overkill. As far as WebAssembly is supported in all the modern browsers I expect to just doing something like |
I think so too but I suspect there will be a period of bootstrapping and then the language revolution should take off. The fact that you can use binaryen to dynamically compile subsequent wasm leads me to think there is an opportunity for radically new toolchains. |
If you get an error like this (with alexanderbys code): |
1 Uncaught (in promise) TypeError: WebAssembly.instantiate(): Import #0 module="wasi_snapshot_preview1" error: module is not an object or function |
I use emscripten and binaryen to compiled c/c++ to wasm file.
Then there is a error in my console.
But when I replace a.out.wasm to http://blog.mikaellundin.name/assets/posts/2016-06-19-creating-a-webassembly-binary-and-running-it-in-a-browser/out.wasm(a wasm file compile by other people), It's ok.
Is there anything wrong when I compile to wasm?
The text was updated successfully, but these errors were encountered: