UPDATE:第一个问题解决了,在这个岗位的底部描述的第二个。在非常简单的GTK2Ç应用,问题设置GNU编译工具
UPDATE2:问题二解决为好。
我想了解如何设置GNU建立一个非常简单的GTK + 2 C应用工具(autoconf的/ automake的)。我已经按照this tutorial和this one that deals with sub directories,但我运行到哪里我的源目录(在src子目录)不产生一个Makefile的问题,虽然是如何产生的父目录的Makefile。
首先,这里是我的文件夹结构:
app/src
- main.c
- main.h
- Makefile.am
app
- configure.ac
- Makefile.am
- aclocal.m4
(... other generated files ...)
这里有重要的文件的内容:
应用程序/ configure.ac:
AC_PREREQ([2.63])
AC_INIT(app, 0.1)
AM_INIT_AUTOMAKE(app, 0.1)
AC_CONFIG_SRCDIR([src/main.h])
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_CONFIG_FILES([Makefile], [src/Makefile])
AC_OUTPUT
应用程序/ Makefile.am :
SUBDIRS = src
应用程序/ src目录/ Makefile.am:
bin_PROGRAMS = app
app_SOURCES = main.c
app_LDADD = `pkg-config --cflags --libs gtk+-2.0`
这是当我运行下面的命令会发生什么:
$ autoconf
$ automake -a
$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
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... none
configure: creating ./config.status
config.status: creating Makefile
./config.status: line 1153: src/Makefile: No such file or directory
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
当我检查,主要app文件夹获得一个Makefile和Makefile.in,但src文件夹仍然只有Makefile.am。有任何想法吗?
UPDATE:我由通过ADL提到的变化,即,我删除从AC_CONFIG_FILES命令的方括号和逗号和除去从AM_INIT_AUTOMAKE命令应用名称/版本。我还将src/Makefile.am中的app_LDADD命令更改为app_LDFLAGS。这已经解决了我没有通过配置的最初问题,但现在它不在寻找gtk库。当我做一个让我得到类似如下:
$ make
make all-recursive
make[1]: Entering directory `/home/adam/Development/app-0.1'
Making all in src
make[2]: Entering directory `/home/adam/Development/app-0.1/src'
if gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -MT main.o -MD -MP -MF ".deps/main.Tpo" \
-c -o main.o `test -f 'main.c' || echo './'`main.c; \
then mv -f ".deps/main.Tpo" ".deps/main.Po"; \
else rm -f ".deps/main.Tpo"; exit 1; \
fi
main.c:3:21: error: gtk/gtk.h: No such file or directory
In file included from main.c:4:
main.h:4: error: expected specifier-qualifier-list before ‘GtkWidget’
以下是我与pkg配置:
$ pkg-config --libs --cflags gtk+-2.0
-D_REENTRANT -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lgio-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lglib-2.0
我敢肯定,我做错了什么,我SRC/Makefile.am,但我不知道是什么。如果有帮助,我的配置脚本似乎没有寻找任何gtk库。
UPDATE2:
所以对于UPDATE1问题基本解决似乎是我需要以下检查添加到我的configure.ac文件:
PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.12])
PACKAGE_CFLAGS="-g -Wall $GTK_CFLAGS"
PACKAGE_LIBS="-g $GTK_LIBS"
PACKAGE_LDFLAGS="-export-dynamic $GTK_LDFLAGS"
AC_SUBST([PACKAGE_CFLAGS])
AC_SUBST([PACKAGE_LIBS])
AC_SUBST([PACKAGE_LDFLAGS])
这被添加到AC_PROG_CC下的程序检查部分。这是告诉configure检查gtk + -2.0库。大写的GTK似乎是一个任意的变量名,并且CFLAGS,LIBS和LDFLAGS(可能更多)被动态添加到它,以便您可以生成PACKAGE_ *变量。 AC_SUBST似乎可以让你访问Makefile.am中的PACKAGE *变量。仅供参考,添加了-export-dynamic标志,以便您可以使用glade/gtkbuilder文件(我相信还有其他原因,但我仍然处于非常基本的理解水平)。
在SRC/Makefile.am,你应该有:
bin_PROGRAMS = app
app_SOURCES = main.c main.h
app_LDADD = @[email protected]
app_LDFLAGS = @[email protected]
INCLUDES = @[email protected]
这似乎是所有你需要一个基本的GTK + -2.0Ç应用。它实际上激发了我编写一个简单的教程来设置使用autotools的C gtk应用程序。最近在这个领域的初学者文献/信息明显缺乏。
感谢您的回答!这解决了我的第一个问题,但它发现了我的帖子底部提到的第二个问题。 – 2009-07-05 14:16:50