Reputation: 535
I'm now playing with LLVM and it's JIT. I'm pretty interested in the JIT and then I wrote a small GTK+ hello world:
#include <gtk/gtk.h>
int main ()
{
gtk_init(NULL, NULL);
GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (win, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *lbl = gtk_label_new ("hello world");
gtk_container_add (GTK_CONTAINER (win), lbl);
gtk_widget_show_all (win);
gtk_main();
return 0;
}
I compiled it into Bitcode this way:
clang -emit-llvm -S a.c `pkg-config --cflags gtk+-3.0`
llvm-link a.s -o a.o
But when I run it
> lli a.o
LLVM ERROR: Program used external function 'gtk_init' which could not be resolved!
I tried to find out how to add an external library when linking, but I found nothing. Is there a way to let it run?
Upvotes: 0
Views: 4977
Reputation: 9324
llvm-link is a not a "usual" linker. It's used to merge several IR files. So, in your case a.o is just a binary LLVM IR and everything worked because llvm-link automagically parsed textual LLVM IR.
You cannot "link in" the native libraries. Though, you can load them into lli process (e.g. via LD_PRELOAD) and symbols are supposed to be resolved.
Upvotes: 5