1.windows下安装gtk3开发环境
https://www.gtk.org/docs/installations/windows/#using-gtk-from-msys2-packages
2.安装帮助说明
pacman -Ss devhelp //查询可用的包
pacman -S mingw64/mingw-w64-x86_64-python3-sphinxcontrib-devhelp //安装64位即可
3.安装gcc开发工具
pacman -S mingw-w64-x86_64-toolchain base-devel
回车-回车-y(全部安装)
如需配置代理:
export http_proxy="ProxyIp:Port"
export https_proxy="ProxyIp:Port"
例如:
export http_proxy="192.168.1.200:8080"
export https_proxy="192.168.1.200:8080"
4.编译测试(见附件)
测试源码test.c
#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *label;
//初始化GTK+库
gtk_init(&argc, &argv);
//创建主窗口
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
//设置窗口大小
gtk_widget_set_size_request(window,300,300);
//设置标题
gtk_window_set_title(GTK_WINDOW (window), "Hello World");
//当窗口即将被销毁,停止主GTK+循环
g_signal_connect(window, "destroy",G_CALLBACK (gtk_main_quit), NULL);
//创建一个"Hello World"标签
label = gtk_label_new("Hello, World");
//将标签加入到主窗口
gtk_container_add(GTK_CONTAINER (window), label);
//设置窗口中的所有元素可见
gtk_widget_show_all(window);
//开始主循环,让它在那里休息,直到应用程序关闭
gtk_main();
return 0;
}
编译脚本build.sh
#!/bin/sh
export app=test.exe
rm -rf ${app}
echo "clean up ${app}"
echo "building ${app}"
gcc test.c -s -o2 -Wl,-subsystem,windows -o ${app} `pkg-config --cflags --libs gtk+-3.0`
echo "build ${app} ok"
打开msys2 64 bat控制台:
cd /home/xxx/gtkapp
./build.sh
5.运行结果
./test.exe或双击test.exe即可