C语言网

 找回密码
 加入社区!

QQ登录

只需一步,快速开始

查看: 233|回复: 0

gtk+_automake简易流程 [复制链接]

Rank: 3Rank: 3

主题
0
帖子
174
C币
956 枚
在线时间
32 小时
发表于 2010-3-12 11:17:50 |显示全部楼层
首先,编写一个简单的GTK+程序gtkhello.c:
/*
* gtkhello.c
*
*  Created on: 2010-1-28
*      Author: young
*/

#include <gtk/gtk.h>

int main(int argc, char *argv[]) {
GtkWidget *wnd;
GtkWidget *label;

gtk_init(&argc, &argv);

wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(wnd), "Hello GTK+!");
gtk_window_set_default_size(GTK_WINDOW(wnd), 300, 200);

label = gtk_label_new("Hello, welcome to the GTK+ world in Ubuntu 9.10\n\n(C) 2010 Chinsoft Studio");
gtk_container_add(GTK_CONTAINER(wnd), label);

g_signal_connect(GTK_OBJECT(wnd), "destroy", G_CALLBACK(gtk_main_quit), NULL);

gtk_widget_show_all(wnd);
gtk_main();

return 0;
}

接下来,我们开始使用automake等命令编写Makefile文件。


(1)
在终端中运行autoscan命令;
young@young-laptop:~/workspace/gtks/gtkhello$ ls -l
总计 8
-rw-r--r-- 1 young young   0 2010-01-28 21:35 autoscan.log
-rw-r--r-- 1 young young 470 2010-01-28 21:35 configure.scan
-rw-r--r-- 1 young young 720 2010-01-28 21:35 gtkhello.c

(2)
使用mv命令将onfigure.scan重命名为configure.acconfigure.in并修改文件内容:

修改前文件:
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.64])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([gtkhello.c])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_OUTPUT

修改后文件:
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.64])
AC_INIT(gtkhello, 1.10.01, yyhoo2.young@gmail.com)
AC_CONFIG_SRCDIR([gtkhello.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE(gtkhello,1.10.01)

# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
AM_PATH_GTK_2_0(2.2.0,,AC_MSG_ERROR(gtkhello 0.1 needs GTK+ 2.2.0))

AC_OUTPUT(Makefile)

(3)
在当前目录下新建Makefile.am文件,文件内容如下:
bin_PROGRAMS = gtkhello
gtkhello
_SOURCES = gtkhello.c
AM_CPPFLAGS  = @GTK_CFLAGS@
LDADD = @GTK_LIBS@


(4)
在当前目录下使用touch命令新建NEWS README ChangeLog AUTHORS 四个文件,否则运行automake --add-missing命令时将会报错;

(5)
在终端中依次运行以下命令:
aclocal
autoheader
autoconf
automake --add-missing

(6)
如果没有任何错误,继续运行./configure命令:
young@young-laptop:~/workspace/gtks/gtkhello$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for pkg-config... /usr/bin/pkg-config
checking for GTK+ - version >= 2.2.0... yes (version 2.18.3)
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
即生成Makefile文件。

(7)
使用make命令即可编译gtkhello.c程序。
注:如果您使用的是Ubuntu操作系统,请使用sudo apt-get install命令安装automake等工具命令。此外本文中的程序在Ubuntu 9.10 Redhat 企业版 5.0上均已通过测试。
您需要登录后才可以回帖 登录 | 加入社区!

C语言 ( 粤ICP备11042647号-2 )

GMT+8, 2012-2-6 13:49

©2009-2011 cyuyan.com.cn

回顶部