#Compile C code that uses stdlib to WASM/WASI

1 messages · Page 1 of 1 (latest)

gritty isle
#

How can I compile the following code with --target wasm32-wasi?

#include <math.h>

float compute(double x) {
    return sin(x);
}

I tried:

>zig build-exe wasm.c -target wasm32-wasi
error(compilation): clang failed with stderr: wasm.c:1:10: fatal error: 'math.h' file not found

wasm.c:1:1: error: unable to build C object: clang exited with code 1

How to solve that? Doesn't WASI provide those libraries? Can I (and should I) compile them statically?

lethal bone
#

you need to link libc

#
zig build-exe wasm.c -target wasm32-wasi -lc
#

im not sure if there's actually a wasi libc, i guess you'll find out :)