wasm file path issue

518 views
Skip to first unread message

Guillaume Rouault

unread,
May 9, 2018, 7:51:15 AM5/9/18
to emscripten-discuss
Hi, 
 I am very new to compiling, just trying to play with some C code ( very new to C also ) and compiling it to wasm.
I have been pretty successful so far : 

I have managed to compile some C code with :
emcc main.c -s WASM=1 --separate-asm -o build/aaa.html

My issue is : 
 when executing aaa.js with Node, it only works if I cd into the build/ directory, and I have the same issue when I try to include this into a web project.
I don't if the issue is with emcc , javascript or nodejs... 
To make it short, I'm a little lost ... 

node build/aaa.js //returs an error
cd build
node aaa.js //works fine

Alon Zakai

unread,
May 9, 2018, 4:08:45 PM5/9/18
to emscripten-discuss
The JS needs to find the wasm file, and if it is in another directory it gets confused. I think by default we just look in the current dir, and let people customize that using


I'm not sure if there's a way for the JS to say "is the wasm file in the same directory as me" (__file__ in C or Python) in a cross-environment way (web, node, JS shells), but if there were that would be good for us to use.

Another option is to use -s SINGLE_FILE=1 to create a single file for everything (but embedding the wasm in the JS is less efficient).


--
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-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Guillaume Rouault

unread,
May 10, 2018, 4:17:23 AM5/10/18
to emscripten-discuss
Thank Alon, it's seems more logical now :) 
 I modified emcc  compile command like so :

emcc main.c -s WASM=1 --pre-js build/pre.js -o build/aaa.js

and I wrote this into the prej.js file :
var Module = {
    'locateFile' : 'build/aaa.wasm'
}

After compilation I can find this code was added to aaa.js
But I still get the same issue, that is : an error complaining that the wasm file should be found one directory up.
abort({"errno":-4058,"code":"ENOENT","syscall":"open","path":"D:\\CODE\\web_playground\\web_assembly\\c\\aaa.wasm"}) at Error
    at jsStackTrace (D:\CODE\web_playground\web_assembly\c\build\aaa.js:1004:13)
    at stackTrace (D:\CODE\web_playground\web_assembly\c\build\aaa.js:1021:12)
    at abort (D:\CODE\web_playground\web_assembly\c\build\aaa.js:2430:44)
    at getBinary (D:\CODE\web_playground\web_assembly\c\build\aaa.js:1531:7)
    at D:\CODE\web_playground\web_assembly\c\build\aaa.js:1550:15
    at new Promise (<anonymous>)
    at getBinaryPromise (D:\CODE\web_playground\web_assembly\c\build\aaa.js:1549:12)
    at instantiateArrayBuffer (D:\CODE\web_playground\web_assembly\c\build\aaa.js:1610:7)
    at doNativeWasm (D:\CODE\web_playground\web_assembly\c\build\aaa.js:1632:7)
    at Object.Module.asm (D:\CODE\web_playground\web_assembly\c\build\aaa.js:1712:15)
node.js exiting due to unhandled promise rejection


Am I doing it wrong ? 

Thanks a lot

Guillaume Rouault

unread,
May 10, 2018, 4:24:50 AM5/10/18
to emscripten-discuss
Oups, 
 so Module.locateFile must be a method ( of course !!!): 

I modified the prej.js code 
var Module = {
    'locateFile' : function(wasmBinaryFile){ return 'build/aaa.wasm'}
}

And now it work as expected 
Thank you so much 

Reply all
Reply to author
Forward
0 new messages