I think it should work as you expect. For example,
#include <stdio.h>
int main() {
printf("%p\n", fopen("src/webGLWorker.js", "rb"));
}
built with
./emcc a.cpp --preload-file src/ -o a.html
in the emscripten root directory will succeed to fopen that file (which indeed exists under src/).
You can inspect the output JS file to see the preloaded file code. For example in the output from that command, it contains this metadata for that file that is opened:
{"start": 2376860, "audio": 0, "end": 2419578, "filename": "/src/webGLWorker.js"}
Some possible issues might be if you are in another directory, or the preloading failed due to a network error, etc. (can use the network tab in devtools to debug stuff like this).
- Alon