Search code examples
cclangllvmwebassemblyllc

OSX - Compile to WebAssembly with llc "llc: : error: unable to get target for 'wasm32', see --version and --triple."


I'm running on OSX and trying to compile following c code to webAssembly:

void test(){
    //do stuff
}

I've looked at this example and tried running the following commands:

clang -emit-llvm --target=wasm32 -Oz test.c -c -o test.bc
llc -asm-verbose=false -o test.s test.bc 

First command works fine and clang generates the .bc file, but when I try to run the second command I get:llc: : error: unable to get target for 'wasm32', see --version and --triple.

Any help would be appreciated.


Solution

  • It looks like your version of llvm was not compiled with support for the WebAssembly backend. This backend is still experimental so you need to enable it at cmake time with: -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly