llvm-link with external libraries

匿名 (未验证) 提交于 2019-12-03 00:59:01

问题:

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   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?

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!