我从here下载 gtk + -bundle_3.4.2-20130513_win64.zip
我已经在" C:/ gtk3 /" 上提取了它 我已将目录添加到%PATH%变量;
我复制了这个hello.c代码:
#include <gtk/gtk.h>
static void
activate (GtkApplication* app,
gpointer user_data)
{
GtkWidget *window;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
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;
}
(反叛者不能在我的cmd上工作,所以我将命令复制到文本文件并使其成为一个简单的Makefile)
pkg-config --cflags gtk+-3.0
输出:
-mms-bitfields -IC:/gtk3/include/gtk-3.0 -IC:/gtk3/include/cairo -IC:/gtk3/include/pango-1.0 -IC:/gtk3/include/atk-1.0 -IC:/gtk3/include/cairo -IC:/gtk3/include/pixman-1 -IC:/gtk3/include -IC:/gtk3/include/freetype2 -IC:/gtk3/include -IC:/gtk3/include/libpng15 -IC:/gtk3/include/gdk-pixbuf-2.0 -IC:/gtk3/include/libpng15 -IC:/gtk3/include/glib-2.0 -IC:/gtk3/lib/glib-2.0/include
和
pkg-config --libs gtk+-3.0
输出
-LC:/gtk3/lib -lgtk-3 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lpangocairo-1.0 -lpangoft2-1.0 -lfreetype -lfontconfig -lpangowin32-1.0 -lgdi32 -lpango-1.0 -lm -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl
然后我把整个命令放在像这样的Makefile中
gcc hello.c $(pkg-config --cflags gtk+-3.0) $(pkg-config --libs gtk+-3.0)
我也尝试了所有可能的命令,例如:
gcc $(pkg-config --cflags gtk+-3.0) hello.c $(pkg-config --libs gtk+-3.0)
和
gcc $(pkg-config --cflags gtk+-3.0) $(pkg-config --libs gtk+-3.0) hello.c
和
gcc hello.c $(pkg-config --libs gtk+-3.0) $(pkg-config --cflags gtk+-3.0)
和
gcc $(pkg-config --libs gtk+-3.0) hello.c $(pkg-config --cflags gtk+-3.0)
在上述所有内容中,当我使用gcc编译时,我得到了这个
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0xd): undefined reference to `gtk_application_window_new'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0x15): undefined reference to `gtk_window_get_type'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0x28): undefined reference to `g_type_check_instance_cast'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0x38): undefined reference to `gtk_window_set_title'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0x3d): undefined reference to `gtk_window_get_type'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0x50): undefined reference to `g_type_check_instance_cast'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0x68): undefined reference to `gtk_window_set_default_size'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0x73): undefined reference to `gtk_widget_show_all'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0x97): undefined reference to `gtk_application_new'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0xcf): undefined reference to `g_signal_connect_data'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0xd4): undefined reference to `g_application_get_type'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0xe8): undefined reference to `g_type_check_instance_cast'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0xfe): undefined reference to `g_application_run'
C:\Users\XXX\AppData\Local\Temp\ccRxa5F2.o:hello.c:(.text+0x10e): undefined reference to `g_object_unref'
collect2.exe: error: ld returned 1 exit status
我使用的是Windows 7 64位和cmd
我做错了什么?
答案 0 :(得分:-2)
问题可能是由编译器或GTK3包引起的 解决方案:卸载所有内容,下载MSYS2并下载所需的软件包 (您可以在他们的网站上找到如何通过MSYS搜索和安装软件包) (网站在GTK3的官方下载页面中提供)
然后一切正常, 无论如何,谢谢