Ubuntu安装GTK+教程

Step 1

修改清华源(修改完可提高下载速度)

先运行

sudo gedit /etc/apt/sources.list

替换文本内容,保存,退出。

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

运行一下命令更新一下。

sudo apt-get update

Step 2:

安装GTK

//1安装gcc/g++/gdb/make 等基本编程工具
sudo apt-get install build-essential

//2安装 libgtk2.0-dev libglib2.0-dev 等开发相关的库文件
sudo apt-get install gnome-core-devel

//3用于在编译GTK程序时自动找出头文件及库文件位置
sudo apt-get install pkg-config

//4安装 devhelp GTK文档查看程序
sudo apt-get install devhelp

//5安装 gtk/glib 的API参考手册及其它帮助文档
sudo apt-get install libglib2.0-doc libgtk2.0-doc

//6安装基于GTK的界面GTK是开发Gnome窗口的c/c++语言图形库 
sudo apt-get install glade libglade2-dev

//7安装gtk2.0 或者 将gtk+2.0所需的所有文件统通下载安装完毕
sudo apt-get install libgtk2.0-dev

Step 3

验证是否安装成功

//1查看 2.x 版本
pkg-config --modversion gtk+-2.0

//2查看pkg-config的版本
pkg-config --version

//3查看是否安装了gtk
pkg-config --list-all grep gtk

 

用一个简单的程序测试一下

 1 #include <gtk/gtk.h>
 2 
 3 int main(int argc, char *argv[])
 4 {
 5     GtkWidget   *window;
 6     GtkWidget   *label;
 7     
 8     gtk_init(&argc,&argv);
 9     
10     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
11     gtk_window_set_title(GTK_WINDOW(window),"title");
12     /*
13     label = gtk_label_new("label");
14     gtk_container_add(GTK_CONTAINER(window),label);
15     */
16     
17     // connect the destroy signal of the window to gtk_main_quit
18     // when the window is about to be destroyed we get a notification and
19     // stop the main GTK+ loop
20     
21     g_signal_connect(window,"destroy",G_CALLBACK(gtk_main_quit),NULL);
22 
23     gtk_widget_show_all(window);
24     
25     // start the main loop, and let it rest until the application is closed
26     gtk_main();
27     
28 
29     return 0;
30 }

编译

gcc -o ggg gtk.c `pkg-config --cflags --libs  gtk+-2.0`

运行

./ggg

运行时有警告,忽视即可。

Ubuntu安装GTK+教程

上一篇:vmware workstation安装国产化UOS


下一篇:Ubuntu下PyCharm中添加pandas等包时常见问题