樹心幽徑

« 20180519在ubuntu建ilvssell資料庫及連線用戶treehrt並新增一個資料表new_cust及二筆資料 | Main | 20180525在ubuntu1604裝GTK2.0 examples »

20180525在ubuntu1604裝GTK3.0並編寫一個gtk範例程式
2018/05/25,21:54

(1)

treehrt@treehrt-fire:~$ sudo apt-get install build-essential
[sudo] password for treehrt:
正在讀取套件清單... 完成
正在重建相依關係         
正在讀取狀態資料... 完成
build-essential is already the newest version (12.1ubuntu2).

 

(2)

treehrt@treehrt-fire:~$ sudo apt-get install libgtk-3-dev

:

Processing triggers for libc-bin (2.23-0ubuntu10) ...

 

(3)

treehrt@treehrt-fire:~$ sudo apt-get install pkg-config
正在讀取套件清單... 完成
正在重建相依關係         
正在讀取狀態資料... 完成
pkg-config is already the newest version (0.29.1-0ubuntu1).

 

(4)

treehrt@treehrt-fire:~$ sudo apt-get install devhelp

:

設定 devhelp-common (3.18.1-1ubuntu5) ...
設定 libdevhelp-3-2 (3.18.1-1ubuntu5) ...
設定 devhelp (3.18.1-1ubuntu5) ...
設定 libatk1.0-doc (2.18.0-1) ...
設定 libglib2.0-doc (2.48.2-0ubuntu1) ...
設定 libgtk-3-doc (3.18.9-1ubuntu3.3) ...
設定 libpango1.0-doc (1.38.1-1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...

(5)

treehrt@treehrt-fire:~$ pkg-config --cflags --libs gtk+-3.0
-pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/mirclient -I/usr/include/mircore -I/usr/include/mircookie -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0
treehrt@treehrt-fire:~$

(6)

treehrt@treehrt-fire:~$ pkg-config --cflags gtk+-3.0
-pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/mirclient -I/usr/include/mircore -I/usr/include/mircookie -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
treehrt@treehrt-fire:~$

 

(7)

treehrt@treehrt-fire:~$ pkg-config --libs gtk+-3.0
-lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0
treehrt@treehrt-fire:~$

 

(8) 編寫gtk範例程式:參考https://developer.gnome.org/gtk3/stable/gtk-getting-started.html

treehrt@treehrt-fire:~/mysqlc$ vi gtk1.c

treehrt@treehrt-fire:~/mysqlc$ cat gtk1.c
#include <gtk/gtk.h>

static void
activate (GtkApplication* app,
          gpointer        user_data)
{
  GtkWidget *window;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
  gtk_widget_show_all (window);
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}


(9)編繹並執行成功:

treehrt@treehrt-fire:~/mysqlc$ gcc `pkg-config --cflags gtk+-3.0` gtk1.c `pkg-config --libs gtk+-3.0`

treehrt@treehrt-fire:~/mysqlc$ ./a.out

 

 

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType