re: Passing strings from C++ to JavaScript in Web Assembly VIEW POST

re: I would be careful not to use "-s ERROR_ON_UNDEFINED_SYMBOLS=0" for too long, for this may turn build-time errors into run-time ones! The --js-libr...

Good point about the dangers of -s ERROR_ON_UNDEFINED_SYMBOLS=0, thanks!

I'll confess, I haven't explored using the --js-library flag yet. A quick read suggested it wouldn't do what I needed it to do, but I also may just not have read deeply into it enough.


The thing is:
if, in your C++ code, you define something as:

extern int GetFoo();

Then, if you build the code, you'll get an undefined symbol error, UNLESS this function can be "seen" by emscripten. It can only see it if you put it in a js file that it knows of. That is, a file that is passed to the --js-library flag.

What I usually do is something like:

C++: extern "C" void SomeFunction();

JS (in library.js) : SomeFunction : function() { _SomeFunction() }

And _SomeFunction is declared in the JavaScript project where I load the wasm module in.

You can find more details here:


code of conduct - report abuse