the following rust code is failing to compile using wasm32-unknown-emscripten target
extern {
#[link(name="env")]
fn log_event(id: *const u8);
}
fn main() {
unsafe { log_event(::std::ptr::null()); }
}
with
error: unresolved symbol: log_event
correct me if I'm wrong, I might be terrible wrong with this, but #[link]
without kind=static
implies dynamic linking, and the above code should not fail to compile?
As for emscripten itself, it has no problem compiling C code like this:
extern void log_event(void* ptr);
int main() {
log_event(0);
}
with emcc <source above.c> -O3 -s WASM=1 -s SIDE_MODULE=1 -o result.wasm
producing nice import entry in the result.wasm
(import "env" "_log_event" (func (;0;) (type 0)))
So, the question is, is there is any option to have dynamic symbols in the resulting wasm? Or at least override this linker ERROR_ON_UNDEFINED_SYMBOLS
argument at some point?
source link would be:
https://github.com/rust-lang/rust/blob/ec27aa97b921957711b96e578c7c197ff28553ac/src/librustc_back/target/wasm32_unknown_emscripten.rs#L21
@NikVolf actually you can override emcc arguments with help of EMMAKEN_CFLAGS
environment variable.
(assuming your filename is main.rs
)
export EMMAKEN_CFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0"
rustc --target=wasm32-unknown-emscripten main.rs
Most helpful comment
@NikVolf actually you can override emcc arguments with help of
EMMAKEN_CFLAGS
environment variable.(assuming your filename is
main.rs
)