ubuntu安裝GTK

來源:互聯網
上載者:User

我利用此方法成功在UBUNTU 10.04下安裝GTK 2.20.1。

一、安裝

  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、查看1.2.x版本

$pkg-config --modversion gtk+

  2、查看 2.x 版本

$pkg-config --modversion gtk+-2.0

  3、查看pkg-config的版本

$pkg-config --version

  4、查看是否安裝了gtk

$pkg-config --list-all grep gtk

  

三、測試程式

//Helloworld.c
#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 Helloworld Helloworld.c `pkg-config --cflags --libs gtk+-2.0`

  2、運行

$./Helloworld

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.