Ubuntu16.04下安裝GTK+
阿新 • • 發佈:2019-01-06
首先配置源:
略
一、安裝
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
或者
$sudo apt-get install glade-gnome glade-common glade-doc
7、安裝gtk2.0 或者 將gtk+2.0所需的所有檔案統通下載安裝完畢
$sudo apt-get install libgtk2.0-dev
或者
$sudo apt-get install libgtk2.0*
二、檢視GTK庫版本
1、檢視 2.x 版本
$pkg-config --modversion gtk+-2.0
2、檢視pkg-config的版本
$pkg-config --version
3、檢視是否安裝了gtk
$pkg-config --list-all grep gtk
三、測試程式
#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 until the application is closed */ gtk_main(); return0; }
四、編譯執行
1、編譯
$gcc -o Hello Hello.c `pkg-config --cflags --libs gtk+-2.0` 標註部分一定要加上不然編譯錯誤。 其中的‘’不是單引號而是Tab鍵上邊那個·
2、執行
$./Hello