WASM instantiation Error function="_embind_register_void" error: function import requires a callable

468 views
Skip to first unread message

Sohan Jyoti Ghosh

unread,
Oct 13, 2022, 10:30:12 AM10/13/22
to emscripten-discuss
Hi !

I am getting errors while instantiating Array Buffer, 
WebAssembly.instantiate(binary, info)

The error is,
"Uncaught (in promise) RuntimeError: Aborted(LinkError: WebAssembly.instantiate(): Import #1 module="env" function="_embind_register_void" error: function import requires a callable)"

Any pointers, how "env" obj is missing the function ? And how to resolve it ? I am using the JS template coming out of emscripten.
Is there some error in building the .wasm ?  Nothing is reported on the build log though.

Br,
Sohan

Sam Clegg

unread,
Oct 13, 2022, 12:29:54 PM10/13/22
to emscripte...@googlegroups.com
Can you share the full link command you are using?

Can you take a look at the generated JS file?  Do you see the `_embind_register_void` function in that file?  It should be defined as a function then added to the `asmLibraryArg` object which gets passed to instantiate.

cheers,
sam

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/1b7778de-a61c-44fe-9b65-3479dfdbbc1dn%40googlegroups.com.

Sohan Jyoti Ghosh

unread,
Oct 13, 2022, 1:21:07 PM10/13/22
to emscripte...@googlegroups.com
Thanks for getting back.

On Thu, Oct 13, 2022 at 7:29 PM 'Sam Clegg' via emscripten-discuss <emscripte...@googlegroups.com> wrote:
Can you share the full link command you are using?

So, we are trying to build the simple skia hello_world c++ app via wasm, to be playable inside the browser.
We are trying to setup the SDL2 backend for skia with https://skia-review.googlesource.com/c/skia/+/573643 

Here, is our build command for hello_world.wasm, which internally invokes emscripten toolchain
bazel build //example:hello_world_wasm --noincompatible_enable_cc_toolchain_resolution

Can you take a look at the generated JS file?  Do you see the `_embind_register_void` function in that file?  It should be defined as a function then added to the `asmLibraryArg` object which gets passed to instantiate.

The generated JS file (https://gist.github.com/sohanjg/a38f509275b84279e98c097c81c9b5e2) doesnt have `_embind_register_void`. Also the originally generated files somehow wasn't able to load the wasm without throwing errors. So, we changed an existing simple emscripten generated helloworld.js (which was almost identical) to refer to the wasm generated by skia.

cheers,
sam

Br,
Sohan 
On Thu, Oct 13, 2022 at 7:30 AM Sohan Jyoti Ghosh <soh...@chromium.org> wrote:
Hi !

I am getting errors while instantiating Array Buffer, 
WebAssembly.instantiate(binary, info)

The error is,
"Uncaught (in promise) RuntimeError: Aborted(LinkError: WebAssembly.instantiate(): Import #1 module="env" function="_embind_register_void" error: function import requires a callable)"

Any pointers, how "env" obj is missing the function ? And how to resolve it ? I am using the JS template coming out of emscripten.
Is there some error in building the .wasm ?  Nothing is reported on the build log though.

Br,
Sohan

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/1b7778de-a61c-44fe-9b65-3479dfdbbc1dn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

Sam Clegg

unread,
Oct 13, 2022, 4:39:26 PM10/13/22
to emscripte...@googlegroups.com
In general it is not possible to swap the JS and wasm files that emscripten generates.  The JS is highly specific to the wasm module, and not portable between wasm modules.

IIRC many folks have had success compiling skia to wasm already.  Have you looked at https://skia.org/docs/user/modules/canvaskit/?


Sohan Jyoti Ghosh

unread,
Oct 14, 2022, 6:01:38 AM10/14/22
to emscripte...@googlegroups.com
On Thu, Oct 13, 2022 at 11:39 PM 'Sam Clegg' via emscripten-discuss <emscripte...@googlegroups.com> wrote:
In general it is not possible to swap the JS and wasm files that emscripten generates.  The JS is highly specific to the wasm module, and not portable between wasm modules.

Okay, so the problem with using emscripten toolchain from Skia is that the .html file is empty. When we use the template https://github.com/emscripten-core/emscripten/blob/main/src/shell_minimal.html and refer the script to the generated JS. It is not loading the .wasm module (and not throwing any error/warning in the console to understand).
Is the .html generated also very specific ?

We have shared the gist with the JS generated, let us know if anything stands out.

IIRC many folks have had success compiling skia to wasm already.  Have you looked at https://skia.org/docs/user/modules/canvaskit/?

Yes, we are following Canvaskit, the use-case here is little different, in that using Canvaskit, the drawing application/code has to be written with Canvaskit API and JS.
What we are trying to achieve is a C++ based drawing module using native Skia API's, and the whole package would be compiled to wasm.
 

Sohan Jyoti Ghosh

unread,
Oct 18, 2022, 7:17:55 AM10/18/22
to emscripte...@googlegroups.com
Hi !

Thanks for the pointers, the generated JS was indeed very specific.
We are finally able to load the .wasm module with some minor changes in the generated JS (loading via module) . 

Now, we need help to initialize the native code and invoke the functions from JS/HTML ?

The native Application::Create/HelloWorld Ctor we try to use needs some platformData, I wonder how we can provide it from JS/HTML. 

https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/example/HelloWorld.cpp;l=29


We saw how Canvaskit does the initialization https://github.com/google/skia/blob/main/demos.skia.org/demos/hello_world/index.html or how Box2D https://github.com/kripken/box2d.js/blob/master/demo/webgl/box2d.html#L24 

, Bullet(ammo.js) https://github.com/kripken/ammo.js/blob/main/examples/webgl_demo/ammo.html#L56 does.

Are there some other examples we can refer to, to instantiate and control C++ objects/functions from JS.


Br,

Sohan

Sam Clegg

unread,
Oct 18, 2022, 6:48:55 PM10/18/22
to emscripte...@googlegroups.com
On Tue, Oct 18, 2022 at 4:17 AM Sohan Jyoti Ghosh <soh...@chromium.org> wrote:
Hi !

Thanks for the pointers, the generated JS was indeed very specific.
We are finally able to load the .wasm module with some minor changes in the generated JS (loading via module) . 

Now, we need help to initialize the native code and invoke the functions from JS/HTML ?

The native Application::Create/HelloWorld Ctor we try to use needs some platformData, I wonder how we can provide it from JS/HTML. 

https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/example/HelloWorld.cpp;l=29


We saw how Canvaskit does the initialization https://github.com/google/skia/blob/main/demos.skia.org/demos/hello_world/index.html or how Box2D https://github.com/kripken/box2d.js/blob/master/demo/webgl/box2d.html#L24 

, Bullet(ammo.js) https://github.com/kripken/ammo.js/blob/main/examples/webgl_demo/ammo.html#L56 does.

Are there some other examples we can refer to, to instantiate and control C++ objects/functions from JS.


There are several different approaches to interacting with native code.  I would start by reading the docs here:  https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html


Reply all
Reply to author
Forward
0 new messages