wasi-sdk
wasi-sdk copied to clipboard
clang compile targetting wasm failed
I built llvm with setting -DLLVM_TARGETS_TO_BUILD="host;X86;RISCV;WebAssembly" -DLLVM_ENABLE_PROJECTS="llvm;clang;lld;compiler-rt;clang-tools-extra for cmake
chao@DESKTOP-B79IRTG:~$ which clang
/usr/local/llvm/bin/clang
chao@DESKTOP-B79IRTG:~$ llc --version
LLVM (http://llvm.org/):
LLVM version 11.0.0git
Optimized build.
Default target: x86_64-unknown-linux-gnu
Host CPU: skylake
Registered Targets:
riscv32 - 32-bit RISC-V
riscv64 - 64-bit RISC-V
wasm32 - WebAssembly 32-bit
wasm64 - WebAssembly 64-bit
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
I also has installed WASI
chao@DESKTOP-B79IRTG:~$ ls /opt/wasi-sdk/share/wasi-sysroot/
include lib share
Then I tried to compile a helloworld with clang
chao@DESKTOP-B79IRTG:~$ clang helloworld.c --sysroot=/opt/wasi-sdk/share/wasi-sysroot/ --target=wasm32-wasi
wasm-ld: error: cannot open /usr/local/llvm/lib/clang/11.0.0/lib/wasi/libclang_rt.builtins-wasm32.a: No such file or directory
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
Hi!
The builtins need to be installed as well (/usr/local/llvm/lib/clang/11.0.0/lib/wasi/libclang_rt.builtins-wasm32.a).
You can get them by compiling clang_rt from the wasi-sdk package, or directly download them here (libclang_rt.builtins-wasm32-wasi-11.0.tar.gz).
@jedisct1
Thanks !
but after copying the .a I ran into another linker error
chao@DESKTOP-B79IRTG:~/a$ ls /usr/local/llvm/lib/clang/11.0.0/lib/wasi
libclang_rt.builtins-wasm32.a
chao@DESKTOP-B79IRTG:~/a$ clang helloworld.c --sysroot=/opt/wasi-sdk/share/wasi-sysroot --target=wasm32-wasi
wasm-ld: error: /opt/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi/libc.a(__original_main.o): undefined symbol: main
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
Looks like your helloworld.c is missing a main function?
I tried to reproduce this. LLVM HEAD was compiled from source using the configuration above, and the linker found the main function just fine.
clang version 11.0.0 (https://github.com/llvm/llvm-project.git 8799ebbc1f03a348f732fc14242ad4c395076bcc)
Target: aarch64-unknown-linux-gnu
Maybe the version you used needs an update?
If you don’t have a main function, add -mexec-model=reactor to the command line.
I think this is fixed by following @jedisct1's instructions (and this issue is a bit stale); feel free to reopen it if that does not fix the issue.