need help to port existing C library into Webassembly & load it on web environemnt

41 views
Skip to first unread message

Sayantan Sadhukhan

unread,
Sep 3, 2022, 3:31:25 AM9/3/22
to emscripten-discuss
I have Generated to WASM modules using emcmake but when ever i try to load the Module into Web Environment .its not instantiating anyway. need help to load that nodule & use its functions .for example  port Zlib into WebAssembly use the library to compress files

Sam Clegg

unread,
Sep 5, 2022, 2:27:41 PM9/5/22
to emscripte...@googlegroups.com
Emscripten will generate a .js file for that takes care of loading the WebAssembly module.  Are you using the generated .js file?

On Sat, Sep 3, 2022 at 12:31 AM Sayantan Sadhukhan <sayantan....@biswagames.com> wrote:
I have Generated to WASM modules using emcmake but when ever i try to load the Module into Web Environment .its not instantiating anyway. need help to load that nodule & use its functions .for example  port Zlib into WebAssembly use the library to compress files

--
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/040fc901-d9cd-4314-98e3-65d488a5c9bcn%40googlegroups.com.

Sayantan Sadhukhan

unread,
Sep 6, 2022, 7:03:54 AM9/6/22
to emscripten-discuss
no not reaaly,i have generated the wasm & the corresponding js of it.. but im the issues while using it.
i have generated the wasm of a zlib c library ,in return i got 4 wasm files example.wasm ,example64.wasm,minigzip.wasm,mingzip64.wasm 
& their corresponding .js files . i need help to figure out how i can use those modules to compress & decompress files in a web environ ment..

Sam Clegg

unread,
Sep 6, 2022, 9:33:08 AM9/6/22
to emscripte...@googlegroups.com
Take a look at https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html.

Most likely you want to create some kind of wrapper around zlib, or at least build a new program that exports that native Zlib functions that you want to call from JS.  The sample programs that you get with zlib are probably not what you want for running on the web.

If its just zlib you want then you don't even need to compile it yourself since emscripten supplies its own version of zlib when you specify the `-sUSE_ZLIB` command line flag.

For example you could build with `./emcc empty.c -sUSE_ZLIB -sEXPORTED_FUNCTIONS=_inflate` .. then the resulting JS file with have a function called Module._inflate that corresponds to the native inflate function in zlib.   You would also write a wrapper around the inflate function either in JS or in C/C++ that would make it easier to use.  There are several ways to do that listed in the above docs.

cheers,
sam

Reply all
Reply to author
Forward
0 new messages