一、前言
维基百科:GTK(原名GTK+)最初是GIMP的专用开发库(GIMP Toolkit),后来发展为Unix-like系统下开发图形界面的应用程序的主流开发工具之一。GTK是自由软件,并且是GNU计划的一部分。自2019年2月6日起,GTK+改名为GTK。
二、下载地址
已编译好的GTK文件下载地址:
也可以按照官网的方式使用MSYS2进行安装:
The GTK Project - A free and open-source cross-platform widget toolkit
三、VS环境配置
Step1 解压GTK文件到本地
本文使用32位的gtk+3.6.4,解压后文件如下图,根目录设置为Gtk
Step2 添加bin文件夹到环境变量
Windows ==>> 设置 ==>> 系统 ==>> 关于 ==>> 高级系统设置 ==>> 环境变量 ==>> 点击Path ==>> 新建 ==>> 输入bin 文件夹路径 ==>> 确定
Step3 配置Gtk本地环境
输入代码(注意Gtk文件所在位置):
pkg-config --cflags gtk+-3.0
pango-querymodules > D:\Gtk\etc\pango\pango.modules
gdk-pixbuf-query-loaders > D:\Gtk\lib\gdk-pixbuf-2.0\2.10.0\loaders.cache
gtk-query-immodules-3.0 > D:\Gtk\lib\gtk-3.0\3.0.0\immodules.cache
Step4 新建VS项目
#include <gtk/gtk.h>
int main(int argc, char* argv[]) {
GtkWidget* window;
GtkWidget* label;
gtk_init(&argc, &argv);
/* create the main, top level, window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/* give it the title */
gtk_window_set_title(GTK_WINDOW(window), "Hello World");
/* Connect the destroy signal of the window to gtk_main_quit
* When the window is about to be destroyed we get a notification and
* stop the main GTK+ loop
*/
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
/* Create the "Hello, World" label */
label = gtk_label_new("Hello, World");
/* and insert it into the main window */
gtk_container_add(GTK_CONTAINER(window), label);
/* make sure that everything, window and label, are visible */
gtk_widget_show_all(window);
/* start the main loop, and let it rest there until the application is closed */
gtk_main();
return 0;
}
Step5 添加头文件夹
项目 ==>> GtkTest属性 ==>> 配置属性 ==>> C/C++ ==>> 常规 ==>> 附加包含目录
D:/Gtk/include
D:/Gtk/include/atk-1.0
D:/Gtk/include/cairo
D:/Gtk/include/freetype2
D:/Gtk/include/glib-2.0
D:/Gtk/include/gtk-3.0
D:/Gtk/include/libpng15
D:/Gtk/include/pixman-1
D:/Gtk/include/gdk-pixbuf-2.0
D:/Gtk/lib/glib-2.0/include
Step6 添加库文件夹
项目 ==>> GtkTest属性 ==>> 配置属性 ==>> 链接器 ==>> 常规 ==>> 附加库目录
D:/Gtk/lib
Step7 添加库文件
项目 ==>> GtkTest属性 ==>> 配置属性 ==>> 链接器 ==>> 输入 ==>> 附加依赖项
atk-1.0.lib
cairo.lib
fontconfig.lib
gailutil.lib
gdk_pixbuf-2.0.lib
gdk-win32-3.0.lib
gio-2.0.lib
glib-2.0.lib
gmodule-2.0.lib
gobject-2.0.lib
gthread-2.0.lib
gtk-win32-3.0.lib
pango-1.0.lib
pangocairo-1.0.lib
pangoft2-1.0.lib
pangowin32-1.0.lib