fopen failed when using wasi-libc

247 views Asked by At

I tried to use fopen to read an image when using wasi-libc:

#include <stdio.h>

int main()
{
    FILE *f = fopen("test.png", "rb");
    printf("file %p\n", f);
    fclose(f);
}

Build the code with Clang:

$ clang --target=wasm32-wasi --sysroot=/opt/wasi-sdk/share/wasi-sysroot/ test.c -o test.wasm
$ wasmtime test.wasm
$ file 0

It returned NULL. How can I sove the issue?

1

There are 1 answers

0
yushulx On

Fixed:

wasmtime --dir=. test.wasm