DEV Community

Experimenting with Web Assembly and Node.js

Bryan Hughes on March 12, 2019

I've been wanting to play around with Web Assembly for a while, and finally had a chance to. Since I'm a mostly Node.js developer, I wanted to play...
Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Do I need the emscripten glue code?

I am seeing errors like:
LinkError: WebAssembly.instantiate(): Import #1 module="env" function="_emscripten_get_heap_size" error: function import requires a callable

Collapse
 
sudhanshu16 profile image
Sudhanshu Gautam

Hey! I am experiencing the same issue. I have used a 'c' code.
Do you know the solution to this issue?

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Use emscripten and include the JavaScript gluecode and you won't have this issue.

Collapse
 
nebrius profile image
Bryan Hughes

Just to make sure I'm reading this correctly (the timestamps aren't totally clear to me), did your comment on my other post indicate you figured this out?

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Correct, yes your other post helped me figure this part out.

I feel like I am 90% there with my experiment.

Collapse
 
nebrius profile image
Bryan Hughes

I also learned that if you're compiling C++ code with em++ instead of emcc, make sure to include extern "C" in front of any functions in your C++ code that you want to access from JavaScript. Otherwise, you'll get errors that the function can't be found (cause of C++'s complicated name mangling rules).

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Is this why my exported functions are found in c but when I switch to cpp, my functions are undefined. I just refactored in rage for hours.

Collapse
 
nebrius profile image
Bryan Hughes

I bet that's it...if for no other reason because I was also refactoring in rage for some time too before I figured it out!

Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀

Oh man you are absolutely right, I am so happy! that is one of my many questions solved. seems like emscripten can only access C atleast with the similar code that you have. I'm trying to get Lua into node. Its proving ... challenging.

Collapse
 
splugenbrau profile image
SplugenBrau

How long these directions will last valid ??
I mean, DynamSoft site is one year old and is already obsolete.
Must bet Node.js will kill PHP but why learn emscripten now?
And let consider HTML5. Why not learn also?
Where are Webmasters go? Who know?
And CGI is obsolete?
My website rely still on an NGINX system !!!
I just have a headache.
Bye.

Collapse
 
nebrius profile image
Bryan Hughes

Soooo...I just learned that apt-get has an emscripten package. You can install it with sudo apt-get install emscripten and I'm assuming it works the same. I haven't tested it yet though.

Collapse
 
apihlaja profile image
Antti Pihlaja

With fastly moving things like this, you probably don't want to use that method for development setup. For the same reasons you don't install Node.js from default repo.

Collapse
 
nebrius profile image
Bryan Hughes

Agreed, and that is in fact what I ended up discovering.

Collapse
 
johannesvollmer profile image
Johannes Vollmer

Haha, well, launching an entire browser just to run some C is not something you see every day 😁

Collapse
 
nebrius profile image
Bryan Hughes

Good thing I'm not launching a browser 😉