c++cmakellvmbitcode

LLVM bitcode library '.bc' and example of its usage in C++ project


I want to use Apache TVM in WASM environment and for that I have compiled runtime library using LLVM like the tutorial suggests. As the outcome, I have a library with .bc format and a little surfing on the internet has shown that it is LLVM-specific format.

How can I use this .bc file in my C++ project? Obviously, I can not link it as my usual static/dynamic librares. Do I need to recompile it into static .a library, for instance?


Solution

  • That's a LLVM bitcode file. You can convert it into an object file by using llc, like llc -filetype=obj foo.bc.

    You can build the object file as part of an executable (clang++ -o foo foo.o)

    Or you can turn the object file into a suitable binary type, such as a static library. Ex. llvm-ar rcs libfoo.a foo.o. Once you have the library binary, you can link to it how you normally would link to a library of that type. clang++ -o foo -L/path/to/directory/containing/libfoo.a -lfoo