Rust: ERROR_ON_UNDEFINED_SYMBOLS=1 always passed for emcc effectively prevents any dynamic linking

Created on 4 May 2017  ·  1Comment  ·  Source: rust-lang/rust

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

C-bug O-asmjs O-wasm

Most helpful comment

@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

>All comments

@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
Was this page helpful?
0 / 5 - 0 ratings