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

0

を使用した解析を含むプロジェクトでは、次のアプローチを使用しますbison

config.hファイルm4/AC_PROG_BISON.m4に次の行を追加する (automake バージョン 1.11 以下) または追加しない (バージョン 1.12+)ファイルがあります。

/* 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 Docsを参照してください。

于 2014-08-23T12:18:49.557 に答える