5

我在https://github.com/Habbie/autoyacc-problem发布了一个存储库来演示我的问题。

在 automake 1.11 及更低版本中,AC_PROG_YACC在 configure.ac 和AM_YFLAGS=-dMakefile.am 中使用,parser.yy 会变成 parser.cc 和 parser.h。使用 automake 1.12,我得到 parser.cc 和 parser.hh。因为 mybin.cc 有include "parser.h",这意味着 1.12 破坏了我的构建。

我觉得这是一个向后不兼容的变化,但我觉得应该有一种理智的方法来处理这个问题。

展示:

git clone https://github.com/Habbie/autoyacc-problem.git
cd autoyacc-problem/
autoreconf -i
./configure
make

automake 1.11 的结果:构建了 mybin。automake 1.12 的结果:

mybin.cc:1:20: error: parser.h: No such file or directory

帮助!

注意:此示例中没有实际的 C++ 代码,但对于我的实际问题,我确实需要 g++。

4

3 回答 3

2

我不是专家;但考虑到您如何依赖旧版本的 automake 中未记录的行为(请参阅 zhenech),您可以要求更新版本的 automake(因此您可以依赖已定义的行为);或确保预期的文件是由 automake 生成的。

鉴于默认输出扩展名为“.hh”,您可以使用简单的 make 指令从 .h 文件(对于旧版本的 automake)生成 .hh 文件:

.h.hh:
    cp $< $@

如果您更喜欢从 .hh 文件中生成 .h 文件,您可能需要翻转定义,并且根据我不熟悉的 autotools 的 lex/yacc 处理的具体情况,您可能需要将生成的文件添加到 BUILT_SOURCES

于 2013-04-19T08:20:05.553 回答
0

我在涉及使用解析的项目中使用以下方法bison

我有一个文件m4/AC_PROG_BISON.m4,它要么附加(automake 版本 1.11 或更低版本)或不附加(版本 1.12+)以下行到config.h文件:

/* Use *.h extension for parser header file */
#define BISON_USE_PARSER_H_EXTENSION 1

在需要包含解析器生成的标头的文件中,我添加了以下#ifdef 语句:

#include "config.h"
#if defined(BISON_USE_PARSER_H_EXTENSION)
#   include "my_parser.h"
#else
#   include "my_parser.hh"
#endif

另外去把事情做好我将以下行附加到configure.ac

AC_PROG_BISON

现在根据 automake 版本,将包含相关的标题。

文件内容:m4/AC_PROG_BISON.m4

dnl
dnl Check for bison 
dnl AC_PROG_BISON([MIN_VERSION=2.0])
dnl
AC_DEFUN([AC_PROG_BISON], [
if test "x$1" = "x" ; then
    bison_required_version="2.6"
else 
    bison_required_version="$1"
fi

AC_CHECK_PROG(have_prog_bison, [bison], [yes],[no])

AC_DEFINE_UNQUOTED([BISON_VERSION], [0.0],
                   [Defines bison version if bison is not present])

#Do not use *.h extension for parser header file but *.hh
bison_use_parser_h_extension=false

if test "$have_prog_bison" = "yes" ; then
    AC_MSG_CHECKING([for bison version >= $bison_required_version])
    bison_version=`bison --version | head -n 1 | cut '-d ' -f 4`
    AC_DEFINE_UNQUOTED([BISON_VERSION], [$bison_version],
                       [Defines bison version])
    if test "$bison_version" \< "$bison_required_version" ; then
        BISON=:
        AC_MSG_RESULT([no])
        AC_MSG_ERROR([Bison version 2.6 or higher must be installed on the system!])
    else
        AC_MSG_RESULT([yes])
        BISON=bison
        AC_SUBST(BISON)

#Verify automake version
#Upto version 1.11 parser headers for yy files are with h extension, from 1.12 it is hh
        automake_version=`automake --version | head -n 1 | cut '-d ' -f 4`
        AC_DEFINE_UNQUOTED([AUTOMAKE_VERSION], [$automake_version],
                           [Defines automake version])

        if test "$automake_version" \< "1.12" ; then
            #Use *.h extension for parser header file
            bison_use_parser_h_extension=true
            echo "Automake version < 1.12"
            AC_DEFINE([BISON_USE_PARSER_H_EXTENSION], [1],
                      [Use *.h extension for parser header file])
        fi
    fi
else
    BISON=:
    AC_MSG_RESULT([NO])
fi

AM_CONDITIONAL([BISON_USE_PARSER_H_EXTENSION], [test x$bison_use_parser_h_extension = xtrue])
AC_SUBST(BISON)
])
于 2013-10-12T11:30:39.827 回答
0

您可以强制为标头使用特定文件名,包括

%defines "parser.h"

在顶部parser.yy。该选项与没有文件名的-d选项相同。%defines

请参阅GNU Bison 文档

于 2014-08-23T12:18:49.557 回答