Ubuntu16安装GTK+2.0教程

Ubuntu16安装GTK+2.0教程

 

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 

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

#include 

int main(int argc, char *argv[]) { GtkWidget *window; GtkWidget *label; gtk_init(&argc,&argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window),"title"); /* label = gtk_label_new("label"); gtk_container_add(GTK_CONTAINER(window),label); */ // 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); gtk_widget_show_all(window); // start the main loop, and let it rest until the application is closed gtk_main(); return 0; } 

编译

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

运行

./ggg

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

你可能感兴趣的:(Ubuntu16安装GTK+2.0教程)