Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

llvm-link with external libraries

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...