Skip to content

hello_headless example: clang: error: unable to execute command: Executable "wasm-ld" doesn't exist! #1

Description

@guest271314
clang --target=wasm32 -O2 -nostdlib -Iinclude -o examples/hello_headless.wasm examples/hello_headless.c
clang: error: unable to execute command: Executable "wasm-ld" doesn't exist!
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Try with WASI-SDK's lld

clang --target=wasm32 -O2 -nostdlib -Iinclude -fuse-ld=/media/user/x/wasi-sdk/bin/wasm-ld -o examples/hello_headless.wasm examples/hello_headless.c
wasm-ld: error: entry symbol not defined (pass --no-entry to suppress): _start
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Try with -Wl,--no-entry

clang --target=wasm32 -O2 -nostdlib -Iinclude -fuse-ld=/media/user/1ba75ad8-75c6-46d3-a54c-05dc0ceb12b1/wasi-sdk/bin/wasm-ld -Wl,--no-entry -o examples/hello_headless.wasm examples/hello_headless.c

Test. bun can execute WASM

bun examples/hello_headless.wasm
1035 |             };
1036 |           case "wasi_snapshot_preview1":
1037 |             return {
1038 |               wasi_snapshot_preview1: this.wasiImport
1039 |             };
1040 |             throw Error(`No WASI namespace found. Only wasi_unstable and wasi_snapshot_preview1 are supported.
                                                              ^
error: No WASI namespace found. Only wasi_unstable and wasi_snapshot_preview1 are supported.

List of imports:

wapi:io_get (function)
wapi_env:args_count (function)
wapi_filesystem:write (function)
wapi_env:args_get (function)
wapi_clock:time_get (function)
wapi_env:random_get (function)
wapi_filesystem:preopen_count (function)
wapi_filesystem:preopen_path (function)
wapi_filesystem:preopen_handle (function)
wapi_filesystem:open (function)
wapi_filesystem:close (function)

      at getImports (node:wasi:1040:24)
      at /media/user/x/WAPI/examples/hello_headless.wasm:47:56

Bun v1.3.12-canary.1+133681382 (Linux x64 baseline)

Probably a consequence of using WASI-SDK's wasm-ld (ld).

Try wasmtime

wasmtime examples/hello_headless.wasm
Error: failed to run main module `examples/hello_headless.wasm`

Caused by:
    0: failed to instantiate "examples/hello_headless.wasm"
    1: unknown import: `wapi::io_get` has not been defined

Try with --allow-undefined

 clang --target=wasm32 -O2 -nostdlib -Iinclude -fuse-ld=/media/user/x/wasi-sdk/bin/wasm-ld -Wl,--no-entry -Wl,--export-all -Wl,--allow-undefined -o examples/hello_headless.wasm examples/hello_headless.c

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions