gpt4 book ai didi

c - GTK Hello World 提示 undefined reference

转载 作者:行者123 更新时间:2023-12-03 09:57:35 25 4
gpt4 key购买 nike

我正在使用 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ência não definida para”是葡萄牙语,类似于“ undefined reference ”。
有谁知道我需要做什么?

最佳答案

我成功了!问题是,由于某种原因,我的系统错过了 libffi .我下载的是 latest version ,并刚刚安装它:

./configure
(...)
make
(...)
sudo make install
(...)
我已经编译了它,它奏效了!

关于c - GTK Hello World 提示 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63781008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com