所以,我安装gtk+4
了自制软件。我创建了.C
文件并写道:
// Include gtk
#include <gtk/gtk.h>
static void on_activate (GtkApplication *app) {
// Create a new window
GtkWidget *window = gtk_application_window_new (app);
// Create a new button
GtkWidget *button = gtk_button_new_with_label ("Hello, World!");
// When the button is clicked, close the window passed as an argument
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_close), window);
gtk_window_set_child (GTK_WINDOW (window), button);
gtk_window_present (GTK_WINDOW (window));
}
int main (int argc, char *argv[]) {
// Create a new application
GtkApplication *app = gtk_application_new ("com.example.GtkApplication",
G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
return g_application_run (G_APPLICATION (app), argc, argv);
}
我复制了“你好,世界!” 来自www.gtk.org的程序代码。我有错误:
g++ main.cpp -o main `pkg-config --cflags --libs gtk4` && ./main
ld: warning: ignoring file /opt/homebrew/Cellar/gtk4/4.2.1/lib/libgtk-4.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/pango/1.48.9/lib/libpangocairo-1.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/pango/1.48.9/lib/libpango-1.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/cairo/1.16.0_5/lib/libcairo-gobject.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/harfbuzz/2.9.0/lib/libharfbuzz.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/gdk-pixbuf/2.42.6/lib/libgdk_pixbuf-2.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/cairo/1.16.0_5/lib/libcairo.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/graphene/1.10.6/lib/libgraphene-1.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/glib/2.68.4/lib/libgio-2.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/glib/2.68.4/lib/libgobject-2.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/glib/2.68.4/lib/libglib-2.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/opt/gettext/lib/libintl.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
"_g_application_get_type", referenced from:
_main in main-0ae029.o
"_g_application_run", referenced from:
_main in main-0ae029.o
"_g_object_unref", referenced from:
_main in main-0ae029.o
"_g_print", referenced from:
_print_hello in main-0ae029.o
"_g_signal_connect_data", referenced from:
_main in main-0ae029.o
_activate in main-0ae029.o
"_g_type_check_instance_cast", referenced from:
_main in main-0ae029.o
_activate in main-0ae029.o
"_gtk_application_new", referenced from:
_main in main-0ae029.o
"_gtk_application_window_new", referenced from:
_activate in main-0ae029.o
"_gtk_button_new_with_label", referenced from:
_activate in main-0ae029.o
"_gtk_window_get_type", referenced from:
_activate in main-0ae029.o
"_gtk_window_present", referenced from:
_activate in main-0ae029.o
"_gtk_window_set_child", referenced from:
_activate in main-0ae029.o
"_gtk_window_set_default_size", referenced from:
bozich@Antons-Mac-mini ass % gcc main.c `pkg-config --libs gtk4` `pkg-config --cflags gtk4`
ld: warning: ignoring file /opt/homebrew/Cellar/gtk4/4.2.1/lib/libgtk-4.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/pango/1.48.9/lib/libpango-1.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/pango/1.48.9/lib/libpangocairo-1.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/cairo/1.16.0_5/lib/libcairo-gobject.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/harfbuzz/2.9.0/lib/libharfbuzz.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/gdk-pixbuf/2.42.6/lib/libgdk_pixbuf-2.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/cairo/1.16.0_5/lib/libcairo.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/graphene/1.10.6/lib/libgraphene-1.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/glib/2.68.4/lib/libgobject-2.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/glib/2.68.4/lib/libglib-2.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/glib/2.68.4/lib/libgio-2.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/opt/gettext/lib/libintl.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
"_g_application_get_type", referenced from:
_main in main-314cd7.o
"_g_application_run", referenced from:
_main in main-314cd7.o
"_g_object_unref", referenced from:
_main in main-314cd7.o
"_g_print", referenced from:
_print_hello in main-314cd7.o
"_g_signal_connect_data", referenced from:
_main in main-314cd7.o
_activate in main-314cd7.o
"_g_type_check_instance_cast", referenced from:
_main in main-314cd7.o
_activate in main-314cd7.o
"_gtk_application_new", referenced from:
_main in main-314cd7.o
"_gtk_application_window_new", referenced from:
_activate in main-314cd7.o
"_gtk_button_new_with_label", referenced from:
_activate in main-314cd7.o
"_gtk_window_get_type", referenced from:
_activate in main-314cd7.o
"_gtk_window_present", referenced from:
_activate in main-314cd7.o
"_gtk_window_set_child", referenced from:
_activate in main-314cd7.o
"_gtk_window_set_default_size", referenced from:
_activate in main-314cd7.o
"_gtk_window_set_title", referenced from:
_activate in main-314cd7.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我的机器正在使用 ARM64(Apple Silicon M1)。我认为,因此这是错误,但我该如何解决呢?
// 也许我的英语不是很完美,但我希望你能理解我。//也许问题很奇怪,但请帮助我。