Reputation: 1489
So, I have been writing a compiler for a simple lisp using Rust and generating LLVM IR using the Inkwell crate. While trying to find a way to print values to standard output, I came across many answers for using print function just like in C/C++. It seems to work without any problem for the most part.
However, only the function declaration shows up in the generated IR, so it probably means the definition is being linked by llvm itself somewhere(using lli interpreter currently since it's much easier for testing). Anyway, I was just trying to understand where this function is defined. Like is there a core module in llvm where it is defined? Or is using printf dependent on the Unix-like platform instead of being an llvm thing since most llvm functions seem to have "llvm" prefix?
Upvotes: 0
Views: 1514
Reputation: 370172
printf
is defined in the C standard library (libc).
So when you compile your llvm IR to object files and then link them, you'll have to link against a libc to be able to use printf
(note that it's pretty common to link the object files generated by LLVM using a C compiler such as gcc or clang, which will link against a libc automatically).
When using lli
, I believe you get access to any library that lli
itself is linked against and that includes a libc.
Upvotes: 2