【发布时间】:2017-02-07 15:28:24
【问题描述】:
我在 foo.c 中有一个库 foo:
int foo() { return 0; }
我想编译成静态对象foo.o。当我像下面这样直接做时,这行得通。
clang -c foo.c -o foo.o
但是,我想通过 llvm 字节码:
clang -emit-llvm -c foo.c # Compile to LLVM byte code
clang foo.bc -o foo.o # Compile LLVM byte code to native
最后一条命令失败并显示以下错误消息:
/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)
我知道没有 main,因为我编译了一个库,所以这是意料之中的。如何从 LLVM 字节码编译该库?
【问题讨论】:
-
我认为您在 LLVM 案例中将
-c添加到了错误的行中。如果你运行clang foo.bc -c -o foo.o会发生什么?不是答案,因为我完全不确定我是对的;这只是一个猜测。
标签: clang llvm llvm-clang