I have a library foo in foo.c:
int foo() { return 0; }
I want to compile to a static objectfoo.o
. When I do it directly like the following, this works.
clang -c foo.c -o foo.o
However, I want to go via the llvm byte code:
clang -emit-llvm -c foo.c # Compile to LLVM byte code
clang foo.bc -o foo.o # Compile LLVM byte code to native
The last command fails with following error message:
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
clang-3.9: error: linker command failed with exit code 1 (use -v to see invocation)
I know that there is no main, which is expected since I compile a library. How to compile that library from LLVM byte code?