Fedora下搭建gtk开发环境(2014-12-20)
2014-12-20 21:47
387 查看
本周在学习gobject-introspection,很多优质的blog都是从代码讲起的。本想了解一下gi的原理,看着看着发现没有自己跑例程就看不下去了。因此打算自己搭建一个平台测试一下相关代码。由于gi是gtk的升级版本,网络上可供参考的环境搭建多是有关gtk的,所以就有了这个题目“Fedora下搭建gtk开发环境”。
1.搭建过程
(1)在Fedora平台上搜索并安装gtk3.0-dev软件包(Ubuntu等平台只是更换命令即可)
[root@localhost ~]# yum search gtk 3.0 dev
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
相关文章推荐
- 在Fedora上搭建GTK+的开发环境
- Ubuntu下开发环境搭建 C|C++|GTK等
- Windows XP下GTK开发环境搭建
- 全向轮机器人开发之-Fedora+嵌入式环境搭建
- Fedora9 下搭建Qt Creator的ARM开发环境并移植Qt4.6.3-books到mini2440
- Window下GTK开发环境搭建/Code::Blocks开发环境搭建/GLib程序测试
- Fedora9 下搭建Qt Creator的ARM开发环境并移植Qt4.6.3-books到mini2440
- Fedora9/12下搭建Qt Creator的ARM开发环境 并 移植Qt4.6.2到Micro2440(一)
- Fedora9 下搭建Qt Creator的ARM开发环境并移植Qt4.6.3-books到min
- 全向轮机器人开发之-Fedora+嵌入式环境搭建
- Windows下搭建GTK开发环境
- Fedora 9.0下搭建Qt/Embedded 4.5开发环境
- 在64位Fedora14上搭建Android开发环境详解
- Fedora9/12下搭建Qt Creator的ARM开发环境 并 移植Qt4.6.2到Micro2440(二)
- Windows下搭建MinGW+GTK开发环境
- 搭建Fedora13软件开发环境
- Fedora12下搭建Android开发环境
- fedora中搭建gstreamer开发环境
- Fedora12下搭建Qt Creator的ARM开发环境 并 移植Qt4.6.2到Micro2440(一)
- fedora 不启动X11界面;跨平台开发环境的搭建