问题
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
How do I specify linking with -ldl
回答1:
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
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.
In any case, Clang itself can invoke a platform linker - that is actually the default, but of course you have overridden by providing -c.
来源:https://stackoverflow.com/questions/13802383/how-to-link-a-library-with-clang-and-llvm-link