Fedora下搭建gtk开发环境(2014-12-20)

本周在学习gobject-introspection,很多优质的blog都是从代码讲起的。本想了解一下gi的原理,看着看着发现没有自己跑例程就看不下去了。因此打算自己搭建一个平台测试一下相关代码。由于gi是gtk的升级版本,网络上可供参考的环境搭建多是有关gtk的,所以就有了这个题目“Fedora下搭建gtk开发环境”。

1.搭建过程

(1)在Fedora平台上搜索并安装gtk3.0-dev软件包(Ubuntu等平台只是更换命令即可)

[root@localhost ~]# yum search gtk 3.0 dev

已加载插件:langpacks, refresh-packagekit
......

gtk-vnc2-devel.x86_64 : Development files to build GTK3 applications with
                      : gtk-vnc
gtk3-devel.i686 : Development files for GTK+
gtk3-devel.x86_64 : Development files for GTK+
gtk3-devel-docs.x86_64 : Developer documentation for GTK+
......
sugar-toolkit-gtk3-devel.x86_64 : Invokation information for accessing
                                : SugarExt-1.0
  全名和简介匹配 only,使用“search all”试试。

dev软件包是开发所需头文件的集合,需要下载dev包。
可以看到gtk3-devel.x86_64是我需要的开发包(均为x86_64,因为是在64位机上,32位选i686)
[root@localhost ~]# yum install gtk3-devel.x86_64

(2)运行`pkg-config --cflags --libs gtk+-3.0`测试是否通过(Ubuntu可以直接通过)
现在看不到了,只安装gtk+-3.0会报错。因为有包依赖关系。

(3)报错需安装相关的软件包pango-devel和atk-devel(同样x86_64)
[root@localhost ~]# yum install pango-devel.x86_64
[root@localhost ~]# yum install atk-devel.x86_64

(4)继续测试`pkg-config --cflags --libs gtk+-3.0`
[root@localhost ~]# 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/gtk-3.0 -I/usr/include/gio-unix-2.0/ -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/libdrm -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/glib-2.0 -I/usr/lib64/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

测试通过。

2.测试环境

编写简单程序(copy的官方gtk2里example)
[root@localhost arrow]# cat arrow.c

#include <gtk/gtk.h>

/* Create an Arrow widget with the specified parameters
 * and pack it into a button */
GtkWidget *create_arrow_button( GtkArrowType  arrow_type,
				GtkShadowType shadow_type )
{
  GtkWidget *button;
  GtkWidget *arrow;

  button = gtk_button_new ();
  arrow = gtk_arrow_new (arrow_type, shadow_type);

  gtk_container_add (GTK_CONTAINER (button), arrow);
  
  gtk_widget_show (button);
  gtk_widget_show (arrow);

  return button;
}

int main( int   argc,
          char *argv[] )
{
  /* GtkWidget is the storage type for widgets */
  GtkWidget *window;
  GtkWidget *button;
  GtkWidget *box;

  /* Initialize the toolkit */
  gtk_init (&argc, &argv);

  /* Create a new window */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  gtk_window_set_title (GTK_WINDOW (window), "Arrow Buttons");

  /* It's a good idea to do this for all windows. */
  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);

  /* Sets the border width of the window. */
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  /* Create a box to hold the arrows/buttons */
  box = gtk_box_new (FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (box), 2);
  gtk_container_add (GTK_CONTAINER (window), box);

  /* Pack and show all our widgets */
  gtk_widget_show (box);

  button = create_arrow_button (GTK_ARROW_UP, GTK_SHADOW_IN);
  gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 3);

  button = create_arrow_button (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
  gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 3);
  
  button = create_arrow_button (GTK_ARROW_LEFT, GTK_SHADOW_ETCHED_IN);
  gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 3);
  
  button = create_arrow_button (GTK_ARROW_RIGHT, GTK_SHADOW_ETCHED_OUT);
  gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 3);
  
  gtk_widget_show (window);
  
  /* Rest in gtk_main and wait for the fun to begin! */
  gtk_main ();
  
  return 0;
}

[root@localhost arrow]# gcc arrow.c -o arrow.o `pkg-config gtk+-3.0 --cflags --libs`
[root@localhost arrow]# ./arrow.o






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值