llvm与外部库的链接 [英] llvm-link with external libraries

查看:365
本文介绍了llvm与外部库的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用LLVM,它是JIT.我对JIT非常感兴趣,然后写了一个小GTK +的hello世界:

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;
}

我以这种方式将其编译为Bitcode:

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

但是当我运行它

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

推荐答案

llvm-link不是一个常规"链接器.它用于合并多个IR文件.因此,在您的情况下,a.o只是一个二进制LLVM IR,而所有事情都起作用,因为llvm-link自动解析了文本LLVM IR.

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.

您不能链接"本机库.不过,您可以将它们加载到lli进程中(例如通过LD_PRELOAD),并且应该解析符号.

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.

这篇关于llvm与外部库的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆