我使用最新的GTK +成功构建了一个简单的hello world应用程序。我使用msys2来安装所有依赖项,包括GTK +,编译和链接程序。当跑步它应该打开一个新窗口,但没有任何反应。在gdb下运行时,它会显示已创建的新线程。即使我使用eclipse CDT进行构建,也存在同样的问题。使用eclipse,我可以在调用g_application_run
之前设置一个断点。 app变量等所有变量看起来都有效。有什么可能导致这个问题的指针?
请点击此处查看堆栈跟踪: https://imgur.com/dHlaw09
我还使用了一个最新的源包并使用msys2构建它。演示样本也存在同样的问题。例如gtk3-demo.exe。
代码:
#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;
}
永远不会调用activate函数。我没有gtk的来源所以不能介入g_application_run。
编译命令:
g++ -I"C:\msys64\opt\gtk\include\gtk-3.0" -I"C:\msys64\mingw64\include\glib-2.0" -O0 -g3 -Wall -c -essage-length=0 -mms-bitfields -pthread -mms-bitfields -I/mingw64/include/gtk-3.0 -I/mingw64/include/cairo -I/mingw64/include -I/mingw64/include/pango-1.0 -I/mingw64/include/atk-1.0 -I/mingw64/include/cairo -I/mingw64/include/pixman-1 -I/mingw64/include -I/mingw64/include/freetype2 -I/mingw64/include/libpng16 -I/mingw64/include/harfbuzz -I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include -I/mingw64/include/freetype2 -I/mingw64/include -I/mingw64/include/harfbuzz -I/mingw64/include -I/mingw64/include/libpng16 -I/mingw64/include/gdk-pixbuf-2.0 -I/mingw64/include/libpng16 -I/mingw64/include -I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include -MMD -MP -MF"main.d" -MT"main.o" -o "main.o" "../main.cpp"
链接命令:
g++ ./main.o -mwindows -L/opt/gtk/lib -L/mingw64/lib -L/mingw64/lib -lgtk-3 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lz -lepoxy -lpangocairo-1.0 -lpangoft2-1.0 -lpangowin32-1.0 -lgdi32 -lusp10 -lpango-1.0 -lm -latk-1.0 -lcairo-gobject -lcairo -lz -lpixman-1 -lfontconfig -lexpat -lfreetype -liconv -lexpat -lfreetype -lbz2 -lharfbuzz -lm -lgraphite2 -lpng16 -lz -lgdk_pixbuf-2.0 -lm -lpng16 -lz -lgio-2.0 -lz -lgmodule-2.0 -pthread -lgobject-2.0 -lffi -lglib-2.0 -lintl -pthread -lws2_32 -lole32 -lwinmm -lshlwapi -lpcre -lintl -lpcre -o "FabEngineGui.exe"
我使用eclipse CDT配置为使用msys64位环境来构建它。我也尝试直接使用msys2 shell,结果相同。
echo $MSYSTEM
MINGW64