从LLVM位code编译对象时,不能防止静电库链接。 [英] Can't link against static library when compiling objects from LLVM bitcode.
本文介绍了从LLVM位code编译对象时,不能防止静电库链接。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个LLVM编译通。我运行以下列方式一通:
-
编译到LLVM位code
铛foo.c的-emit-LLVM -c -o foo.bc
-
通过选择运行foo.bc(错误仍然出现没有这一步)
-
编译回到一个目标文件
铛-c -o foo.o的foo.bc
-
现在foo.o的可能是一个静态库的一部分。
AR RC libfoo.a中foo.o的
-
我无法对libfoo.a中链接时我所有的C文件以这种方式进行编译。
铛libfoo.a中linkme.o -o linkmelinkme.o:linkme.bc:主要功能:错误:未定义引用'富'
铿锵:错误:连接命令,退出code 1(使用-v看看调用)失败
源文件:
foo.c的:
INT美孚(INT一)
{
返回;
}
foo.h中
INT美孚(INT一个);
linkme.c
的#includefoo.h中INT主(INT ARGC,CHAR *的argv [])
{
富(6); 返回0;
}
解决方案
现在我觉得自己很傻。它无关的.BC文件,参数只是排序。
作品:
铛linkme.o libfoo.a中-o linkme
失败:
铛libfoo.a中linkme.o -o linkme
I am developing an LLVM compiler pass. I run a pass in the following way:
Compile to LLVM bitcode
clang foo.c -emit-llvm -c -o foo.bc
Run foo.bc through opt (The error still occurs without this step)
Compile back to an object file
clang -c -o foo.o foo.bc
Now foo.o might be part of a static library.
ar rc libfoo.a foo.o
I am unable to link against libfoo.a when all my c files are compiled in this way.
clang libfoo.a linkme.o -o linkme linkme.o:linkme.bc:function main: error: undefined reference to 'foo' clang: error: linker command failed with exit code 1 (use -v to see invocation)
Source files:
foo.c:
int foo(int a)
{
return a;
}
foo.h
int foo(int a);
linkme.c
#include "foo.h"
int main(int argc, char *argv[])
{
foo(6);
return 0;
}
解决方案
Now I feel silly. It has nothing to do with the .bc files, just the ordering of the arguments.
Works:
clang linkme.o libfoo.a -o linkme
Fails:
clang libfoo.a linkme.o -o linkme
这篇关于从LLVM位code编译对象时,不能防止静电库链接。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文