yglukhov / wasmrt

MIT License
93 stars 10 forks source link

linking error wasm-ld: error: unable to find library -lm #3

Closed alexisad closed 2 years ago

alexisad commented 4 years ago

Hi i tried to add nim protobuf parser into t_hello_world.nim like: import ../wasmrt import nimpb/nimpb etc..

or simple add only "import strutils"

But getting linking error: wasm-ld: error: unable to find library -lm clang: error: lld command failed with exit code 1 (use -v to see invocation)

nixfreak commented 3 years ago

I'm getting the samething using linux. I install llvm and clang on Archlinux.

compiled the t_hello_world.nim in tests I received this.

[nixfreak@chaosArch tests]$ nim c -r --out:t_hello_world.wasm t_hello_world.nim Hint: used config file '/home/nixfreak/.choosenim/toolchains/nim-1.4.2/config/nim.cfg' [Conf] Hint: used config file '/home/nixfreak/.choosenim/toolchains/nim-1.4.2/config/config.nims' [Conf] Hint: used config file '/home/nixfreak/nim/wasmrt/tests/config.nims' [Conf] ........... Hint: clang -shared -o /home/nixfreak/nim/wasmrt/tests/t_hello_world.wasm /home/nixfreak/.cache/nim/t_hello_world_r/stdlib_assertions.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/stdlib_io.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/stdlib_system.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/@m..@swasmrt.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/stdlib_hashes.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/stdlib_math.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/stdlib_sets.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/@mt_hello_world.nim.c.o -lm --target=wasm32-unknown-unknown-wasm -nostdlib -Wl,--no-entry,--allow-undefined,--export-dynamic,--gc-sections,--strip-all [Link] clang-11: warning: argument unused during compilation: '-shared' [-Wunused-command-line-argument] clang-11: error: unable to execute command: Executable "wasm-ld" doesn't exist! clang-11: error: linker command failed with exit code 1 (use -v to see invocation) Error: execution of an external program failed: 'clang -shared -o /home/nixfreak/nim/wasmrt/tests/t_hello_world.wasm /home/nixfreak/.cache/nim/t_hello_world_r/stdlib_assertions.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/stdlib_io.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/stdlib_system.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/@m..@swasmrt.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/stdlib_hashes.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/stdlib_math.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/stdlib_sets.nim.c.o /home/nixfreak/.cache/nim/t_hello_world_r/@mt_hello_world.nim.c.o -lm --target=wasm32-unknown-unknown-wasm -nostdlib -Wl,--no-entry,--allow-undefined,--export-dynamic,--gc-sections,--strip-all'

nixfreak commented 3 years ago

Do I need to install a wasm runtime ? I know it worked for me in nodejs using rust.

nixfreak commented 3 years ago

I had to install wasm-SDK then export wasi. So can compile C to wasm but not nim to wasm yet.

yglukhov commented 2 years ago

Currently, there's a -lm dependency in nim system library. It has to be patched away for emscriptenless wasm.

yglukhov commented 2 years ago

Implemented workaround in 898872bfab3f51999bc00246160401bce43bc099