我正在使用Linux Mint 20学习GTK。我安装了以下软件包以开始使用:
sudo apt-get install build-essential libgtk-3-dev
然后编译Hello World app in C:
#include <gtk/gtk.h>
static void
print_hello (GtkWidget *widget,
gpointer data)
{
g_print ("Hello World\n");
}
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *button_box;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (window), button_box);
button = gtk_button_new_with_label ("Hello World");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_close), window);
gtk_container_add (GTK_CONTAINER (button_box), button);
gtk_widget_show_all (window);
}
int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
作为示例要求,我使用以下命令对其进行了编译:
gcc `pkg-config --cflags gtk+-3.0` -o hello-world-gtk hello-world-gtk.c `pkg-config --libs gtk+-3.0`
但是它没有用,我也不知道为什么。它的输出是:
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwayland-client.so.0: referência não definida para "ffi_type_void@LIBFFI_BASE_7.0"
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwayland-client.so.0: referência não definida para "ffi_call@LIBFFI_BASE_7.0"
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwayland-client.so.0: referência não definida para "ffi_type_uint32@LIBFFI_BASE_7.0"
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwayland-client.so.0: referência não definida para "ffi_type_sint32@LIBFFI_BASE_7.0"
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwayland-client.so.0: referência não definida para "ffi_prep_cif@LIBFFI_BASE_7.0"
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwayland-client.so.0: referência não definida para "ffi_type_pointer@LIBFFI_BASE_7.0"
collect2: error: ld returned 1 exit status
“referêncianãodefinida para”是葡萄牙语中的“ undefined reference for”之类的东西。
有人知道我需要做什么吗?
答案 0 :(得分:2)
我已经做到了!问题是,由于某种原因,我的系统错过了libffi。我下载了latest version,并安装了它:
./configure
(...)
make
(...)
sudo make install
(...)
我已经编译好了,而且有效!