Emscripten: How can I export FS in js file?

Created on 11 Jan 2018  路  4Comments  路  Source: emscripten-core/emscripten

When I use FS in a .js file, the FS is undefine in Module, and I have already used '-s FORCE_FILESYSTEM=1'
the revision is emsdk-1.37.9
How can I use FS in js file?
the js code is shown below
WebCore.FS.writeFile(filename, new Uint8Array(array), { encoding: "binary" });
the tag I used when emcc is
-o web_core.js -s ASSERTIONS=1 -s MODULARIZE=1 -s TOTAL_MEMORY=10241024128 -s FORCE_FILESYSTEM=1 -s TOTAL_STACK=1024102496 -s ALLOW_MEMORY_GROWTH=1 -s EXPORT_NAME="WebCore" --bind --preload-file simkai.ttf --llvm-lto 1 --closure 1

Most helpful comment

Thank you very much! It works after I used -s "EXTRA_EXPORTED_RUNTIME_METHODS=['FS']"

All 4 comments

Try running without closure or without modularizing? Are you then able to access FS?

(Btw, the stack size 1024*1024*96 is remarkably high, in general it's best to have e.g. a few megabytes stack at most, since most of that memory is wasted from other use)

I have tried a simple example use emcc sample.cpp -o sample.js -s FORCE_FILESYSTEM=1锛宐ut there has no Module["FS"] or Module['FS'] in the sample.js.
The sample.cpp just have a simple function.
int add (int x, int y) { return x + y; }
But when I use 1.37.0 there is a FS in Module, is there something wrong in sdk-1.37.9? @juj @kripken

It's not exposed by default as of now, you should add -s "EXTRA_EXPORTED_RUNTIME_METHODS=['FS']".

Thank you very much! It works after I used -s "EXTRA_EXPORTED_RUNTIME_METHODS=['FS']"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

void4 picture void4  路  3Comments

jcfr picture jcfr  路  4Comments

kripken picture kripken  路  4Comments

yahsaves picture yahsaves  路  4Comments

phraemer picture phraemer  路  3Comments