如何链接库和clang和llvm-link [英] How to link a library with clang and llvm-link
问题描述
我正在编译这样的程序,
I am compiling my program like this,
clang++ -O4 -emit-llvm file1.cpp -c -o file1.bc -pthread
clang++ -O4 -emit-llvm file2.cpp -c -o file2.bc -pthread
llvm-link file1.bc file2.bc -o main.ll -S
如何指定与 -ldl
推荐答案
llvm-link
是将LLVM IR文件链接 IR文件;您可以在这里了解详情。它与 ld
没有任何关系,或者链接对象文件。
llvm-link
is a program which "links" together LLVM IR files into a single IR file; you can read more about it here. It does not have any relation to ld
or to linking object files together.
如果你想生成对象代码和/或可执行文件,请参阅以下相关问题:
If you do want to generate object code and/or executables, see these related questions:
- How to generate machine code with llvm
- llvm-link with external libraries
简而言之,您应该使用原生工具进行汇编和链接( as
和 ld
),虽然目前有一些实验支持生成目标文件和链接在LLVM。
In short, you should be using native tools for assembling and linking (as
and ld
, for instance), though there is currently some experimental support for generating object files and for linking in LLVM.
在任何情况下,Clang本身都可以调用一个平台链接器 - 实际上是默认的,但是当然你通过提供 -c
来覆盖。
In any case, Clang itself can invoke a platform linker - that is actually the default, but of course you have overridden by providing -c
.
这篇关于如何链接库和clang和llvm-link的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!