2

I've been playing with LLVM more and ran into a wall trying to do this:

Assuming I have the bitcode of a project (input.bc), I can compile that to an object file (input.o) using llc.

Now if I write a separate file (funcdefs.c) that uses some symbol definitions which are in input.o, is it possible to compile funcdefs.c to its own IR representation using input.o as an include?

I've tried clang -c -emit-llvm input.o funcdefs.c but I don't see anything that looks like it's finding the missing symbol/global definitions.

Thank you for any guidance!

Sigterm
  • 127
  • 7

2 Answers2

0

You need to create an object file for funcdefs.c first and then link it with input.o.

clang -c funcdefs.c -o funcdefs.o
clang funcdefs.o input.o

You can club those into

clang funcdefs.c input.o
harry
  • 970
  • 6
  • 25
0

To use functions from input.o file you need to create input.h file with definition of functions in it. To create such file see How to call the functions in another compiled *.o object files in C and How do I find out what all symbols are exported from a shared object?

Alexander Ushakov
  • 5,139
  • 3
  • 27
  • 50