Generating static library for wasm32-wasi platform

I'm trying to generate a static library for wasm32-wasi that I can statically link to other code for the same platform. My code is here. It requires LLVM 10. If you run build.sh you'll see something like

$ ./build.sh
+ rm -rf target '*.o' '*.wasm' '*.wat'
+ cargo build --target wasm32-wasi --release
   Compiling wasi v0.10.0+wasi-snapshot-preview1
   Compiling rs_static_lib v0.1.0 (/home/omer/wasm_test/rs_static_lib)
    Finished release [optimized] target(s) in 0.37s
+ clang --target=wasm32-wasi main.c -fpic -c -o main.o
+ wasm-ld main.o target/wasm32-wasi/release/librs_static_lib.a -o main.wasm
wasm-ld: error: target/wasm32-wasi/release/librs_static_lib.a(wasi-e811237f932d0d37.wasi.6lr25g8y-cgu.0.rcgu.o): undefined symbol: wasi::lib_generated::wasi_snapshot_preview1::fd_write::h2c481bab96092d8f

I think the problem is that the archive file does not include the wasi library, but I have no idea how to include that. I also tried using this for linking:

wasm-ld -L target/wasm32-wasi/release -lrs_static_lib main.o -o main.wasm

which fails the same way.

How do I link the Rust library (including all of its dependencies) with other programs?

Thanks.

You need to use the clang from the wasi sdk I think.

I forgot the mention, I already tried that. Nothing changes. Same errors.

I also get the same error if I use wasm32-unknown-emscripten target.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.