我用homebrew下载安装好了gtk+3,然后试着编译了一个网上的示例代码:
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
static gboolean delete_event(GtkWidget * widget, GdkEvent * event,
gpointer data) {
gtk_main_quit();
return FALSE;
}
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *label;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(window), "RobberPhex");
gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);
g_signal_connect(window, "delete-event", G_CALLBACK(delete_event), NULL);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
label = gtk_label_new("Hello GTK!");
gtk_container_add(GTK_CONTAINER(window), label);
gtk_widget_show(label);
gtk_widget_show(window);
gtk_main();
return 0;
}
用gcc编译:
gcc testGTK.c -o testGTK `pkg-config --cflags --libs gtk+-3.0`
结果运行的时候出错了,错误信息是:
Dynamic session lookup supported but failed: launchd did not provide a socket path, verify that org.freedesktop.dbus-session.plist is loaded!
(testGTK:62547): Gtk-WARNING **: cannot open display:
结果在Google找了好久都没找到为什么会这样 T T