When I am using -O2 or -O1 optimization with em++ I have no problems, but when I am using -O3 as follows:
em++ -s WASM=1 -O3 .\testFunct.c++
I got the following error when I use "instantiateStreaming" in the Javascript.
App.js:95 Uncaught (in promise) TypeError: WebAssembly.instantiate(): Import #0 module="a" error: module is not an object or function
I tried to add the following in the import:
env: {
a: () => {},
...
...
}
wasi_snapshot_preview1: {
a: () => {},
...
...
}
But I still get the same error.
The module is looking for an module called "a".. so in your example "a" would live alongside "env" and not within it. However, the problem here is that emscripten is performing minifcation of the strings at -O3 which makes writing the loading code by hand tricky.
Are you using the emscripten-generated JS code for loading the wasm module? Emscripten should have generated the JS file alongside the wasm file.
If you don't want to use the emscripten-generated JS (this is highly recommended since the ABI between the wasm module and the JS code can change over time), then you can build with target that when with .wasm
(e.g. -o out.wasm
or use the explicit --oformat=wasm
flag. When you do this it should suppress the minification of the import/export names.