emscripten
emscripten copied to clipboard
Failed to load resource
Please include the following in your bug report:
Version of emscripten/emsdk:
$ emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.5-git (53b38d0c6f9fce1b62c55a8012bc6477f7a42711)
clang version 21.0.0git
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:/msys64/clang64/opt/emscripten-llvm/bin
Failing command line in full:
I was just customize Using files example
from Emscripten Tutorial page:
$ mkdir -p out/static
$ ./emcc test/hello_world_file.cpp -o out/static/hello.mjs --preload-file test/hello_world_file.txt
$ cat > out/index.html << EOL
<!DOCTYPE html>
<html>
<body>
<script type="module">
import initModule from './static/hello.mjs';
initModule({
print: (text) => { document.body.innerText += text + '\n'; }
});
</script>
</body>
</html>
EOL
$ ./emrun out/index.html
Failure from browser console:
Failed to load resource: the server responded with a status of 404 (File not found: <current path>/out/hello.data)
Module hello.mjs search hello.data in out subdirectory (local webserver root). But hello.mjs sould search hello.data from ./static/ supdirecotry where hello.mjs hosted himself.
Then we mode hello.data to out from out/static and run again:
$ mv out/static/hello.data out/
$ ./emrun out/index.html
And see text in browser:
==
This data has been read from a file.
The file is readable as if it were at the same location in the filesystem, including directories, as in the local filesystem where you compiled the source.
==
Indeed it looks like we should loading the preload data file relative to the .mjs files by default.
BTW, have you considered switching from --preload-file to --embind-file the later will embed the data directly into the wasm file saving download size and memory copying.
Sounds good, but where I can read about the --embind-file option more?
https://emscripten.org/docs/porting/files/packaging_files.html#packaging-using-emcc
https://emscripten.org/docs/porting/files/packaging_files.html#packaging-using-emcc
Thanks! Will try it.
BTW, have you considered switching from
--preload-fileto--embind-filethe later will embed the data directly into the wasm file saving download size and memory copying.
Oh, looks like we was speak about the --embed-file option! :smile: