Currently building a wasm module with zig and c, and I want to expose some C functions to be called by the runtime.
I couldn’t figure out how to pass linker flags from zig build…
Have you been using export fn and @export()?
that’s to export zig functions. there are some C functions i want to export directly
sounds like you do actually want @export, so let me be the second to say so!
how??
here’s what i tried
// add.c
int
add_from_c(int a, int b)
{
return a + b;
}
// add.zig
extern fn add_from_c(i32, i32) callconv(.c) i32;
fn addFromZig(a: i32, b: i32) callconv(.c) i32 {
return a + b;
}
comptime {
@export(&addFromZig, .{ .name = "add" }); // works
@export(&add_from_c, .{ .name = "add2" }); // error: export target cannot be extern
}
and dropping the extern keyword gives another error