emscripten-core / emscripten-core/emscripten

dlopen doesn't work with -sWASMFS=1

Open
#18,602 2 comments 0 reactions 0 assignees View on GitHub
wasmfs
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

main.c
`#include
#include
#include

int main() {
void* handle = dlopen("side.wasm", RTLD_NOW);
if (!handle) {
printf("Failed to load library: %s\n", dlerror());
return 1;
}

void (*symbol)();
symbol = dlsym(handle, "print_hello");
if (!symbol) {
printf("Failed to load symbol: %s\n", dlerror());
return 1;
}

symbol();
dlclose(handle);
return 0;
}
`

side.c
`
#include

void print_hello() {
puts("print_hello() has been called");
}
`

expected output: "print_hello() has been called"
real output:
"Failed to load library: Could not load dynamic lib: side.wasm"
"Error: http://localhost:8002/side.wasm: file not found, and synchronous loading of external files is not available"

If I remove "-sWASMFS=1" flag from the build command - everything is OK.

build commands:
emcc side.c -o side.wasm -s SIDE_MODULE
emcc main.c -o main.html -s MAIN_MODULE --preload-file side.wasm -sWASMFS=1

emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.30 (cfe2bdfe2692457cb5f5770672f6e5ccb3ffc2f2)
clang version 16.0.0 (https://github.com/llvm/llvm-project 800f0f1546b2352ba42a4777149afb13cb874fcd)
Target: wasm32-unknown-emscripten
Thread model: posix

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.