红联Linux门户
Linux帮助

AutoConf和AutoMake使用出错求助

发布时间:2011-05-01 21:25:59来源:红联作者:yehg01
[i=s] 本帖最后由 yehg01 于 2011-5-2 15:42 编辑 [/i]

系统:ubuntu 10.04 跪请高手解惑!
1、目标:使用autoconf和automake编译hello.c
#include stdio.h
int main(int argc,char** argv)
{
printf("Hello,GNU!");
return 0;
}

2、错误描述:automake完成后运行./configure时发生错误:
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
./configure: line 4425: Makefile: command not found
3、命令过程:autoscan→configure.in
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT(hello.c)
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE(hello,1.0)
# Checks for programs.
AC_PROG_CC
# Checks for library functions.
AC_OUTPUT (Makefile)
AC_CONFIG_FILES([Makefile])

→aclocal→autoconf→autoheader→Makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.c

→automake --add-missing→ls
aclocal.m4 config.h config.status depcomp Makefile.am stamp-h1
autom4te.cache config.h.in configure hello.c Makefile.in
autoscan.log config.log configure.in install-sh missing
→./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 whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
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
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
./configure: line 4425: Makefile: command not found
***** configure第4425行代码:
4421****if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
4422**** { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
4423****$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
4424****fi
4425****(Makefile)
4426****ac_config_files="$ac_config_files Makefile"
文章评论

共有 1 条评论

  1. yehg01 于 2011-05-02 15:41:30发表:

    [i=s] 本帖最后由 yehg01 于 2011-5-2 15:44 编辑 [/i]

    经过了半天的测试和排查,终于完成目标了,顺便把笔记贴出来晒晒::0wszxc
    累死了!!!

    菜鸟写的autoconf和automake使用入门笔记
    测试系统:FreeBSD m-net.arbornet.org 6.3-PRERELEASE FreeBSD 6.3-PRERELEASE #1
    $ ssh m-net.arbornet.net
    ###***如果你在m-net.arbornet.net没有Linux账户,可以输入newuser建立一个
    一、编写一个hello.c的源代码文档:
    $ mkdir ~/abc
    $ cd ~/abc
    $ touch hello.c
    $ vi hello.c

    # include "stdio.h"
    int main(int argc, char** argv)
    {
    printf("Hello, GNU! ");
    return 0;
    }

    二、 生成configure.scan并编辑为configure.in:
    $ autoscan → cp configure.scan configure.in→vi configure.in →
    ###***原始的configure.in文档:
    # -*- Autoconf -*-
    # Process this file with autoconf to produce a configure script.
    AC_PREREQ(2.61) ←
    AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS) ←
    AC_CONFIG_SRCDIR([hello.c])
    AC_CONFIG_HEADER([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 ←

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

    #AC_PREREQ(2.61) →
    ###***使用aclocal19命令会报错:
    ###***configure.in:4: error: Autoconf version 2.61 or higher is required
    ###***configure.in:4: the top level
    ###***autom4te259: /usr/local/bin/gm4 failed with exit status: 63
    ###***aclocal19: autom4te259 failed with exit status: 63
    ###***将上面的代码注释掉即可排除错误

    AC_INIT(hello.c)
    AC_CONFIG_SRCDIR([hello.c])
    AC_CONFIG_HEADER([config.h])

    AC_CONFIG_FILES([Makefile])
    AM_INIT_AUTOMAKE(hello, 1.0)

    # 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 (Makefile)
    三、 使用aclocal和autoconf生成aclocal.m4和configure文件:
    $ aclocal119 → autoconf →touch Makefile.am →
    # -*- Makefile.am -*-
    AUTOMAKE_OPTIONS= foreign
    bin_PROGRAMS= hello
    hello_SOURCES= hello.c

    四、 使用autoheader
    $ autoheader →
    五、 使用automake生成Makefile.in文件:
    $ automake19 --add-missing
    六、 使用configure生成最终Makefile:
    $ ./configure --prefix=/home/XXX/hello →
    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
    configure: creating ./config.status
    config.status: creating config.h
    ./configure: line 3448: Makefile: command not found
    ###***configure出现错误,按提示修改configure文件:
    $ vi ./configure →
    ###*** 原始的configure文档内容:
    ###*** 3444
    # Use ||, not &&, to avoid exiting from the if with $? = 1, which
    ###*** 3445
    # would make configure fail if this is the last instruction.
    ###*** 3446
    $ac_cs_success || { (exit 1); exit 1; }
    ###*** 3447
    fi
    ###*** 3448
    (Makefile) ←

    --------------------------------------------------------------------------------------------------------------------------
    ###***修改后的configure文档内容:
    ###*** 3448

    # (Makefile)
    ###*** 将3448行的代码注释掉即可。
    七、 最终make前用ls检查文件:
    $ ls →
    Makefile config.h configure.scan
    Makefile.am config.h.in depcomp
    Makefile.in config.log hello.c
    aclocal.m4 config.status install-sh
    autom4te.cache configure missing
    autoscan-2.61.log configure.in stamp-h1

    八、 开始编译并运行测试:
    $ Make
    $ Make install
    $ ~/hello/bin/hello
    Hello, GNU! [XXXX@m-net ~/abc]$
    九、 参考文献及备注事项:
    1、《gcc》 ,freeMi在http://blog.csdn.net的博客,发布于2005年12月04日;
    2、《例解 autoconf 和 automake 生成 Makefile 文件》,http://www.ibm.com,发布于2006 年 9 月 21 日;
    3、《Autoconf/Automake工具组简介》,三踢馒头在http://blog.163.com的博客,发布于2009年11月9日。
    ***关于手工修改configure.in文件,注释掉代码AC_PREREQ(2.61)和configure文件中,注释掉第3448行内容的做法,
    本人怀疑可能有取巧成功的成分,因此如果有高手知道有更正规更科学的解决办法,还请留个回复说明一下,不胜感谢!