Can't link against static library when compiling objects from LLVM bitcode.
c, clang, llvm
Solution
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
Problem
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; } ```