gcc 返回 - /usr/lib64/perl5/CORE/parser.h:17:7:错误:重新定义“union YYSTYPE”

问题描述 投票:0回答:1

Perl 版本:5.26

操作系统 = RHEL 8.7

我刚开始将 Perl 添加到“C”程序中,因此我尝试遵循 perlembed 中的示例,以便我可以在我正在开发的项目中使用它。但是,我遇到了问题,例如

In file included from /usr/lib64/perl5/CORE/perl.h:3939, from interp.c:2:
/usr/lib64/perl5/CORE/parser.h:17:7: error: redefinition of 'union YYSTYPE'
 union YYSTYPE
       ^~~~~~~

(请参阅下面部分中的其他类似错误)

我运行的环境描述如下:

$cat /etc/redhat-release
Red Hat Enterprise Linux release 8.7 (Ootpa)

$ls -la /bin/cc
lrwxrwxrwx. 1 root root 3 Jul 20  2022 /bin/cc -> gcc

$gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
..
..
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.5.0 20210514 (Red Hat 8.5.0-15) (GCC)

$ perl -V
Summary of my perl5 (revision 5 version 26 subversion 3) configuration:

  Platform:
    osname=linux
..
..
..
`PERL_INCLUDE="/usr/lib64/perl5/CORE"`
  @INC:
    /usr/local/lib64/perl5
    /usr/local/share/perl5
    /usr/lib64/perl5/vendor_perl
    /usr/share/perl5/vendor_perl
    /usr/lib64/perl5
    /usr/share/perl5
  
$ perl -MConfig -e 'print $Config{libs}'

returns

-lpthread -lresolv -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat

如果我尝试编译下面的“interp.c”程序

 #include <EXTERN.h>               /* from the Perl distribution     */
 #include <perl.h>                 /* from the Perl distribution     */

 static PerlInterpreter *my_perl;  /***    The Perl interpreter    ***/

 int main(int argc, char **argv, char **env)
 {
PERL_SYS_INIT3(&argc,&argv,&env);
        my_perl = perl_alloc();
        perl_construct(my_perl);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
        perl_parse(my_perl, NULL, argc, argv, (char **)NULL);
        perl_run(my_perl);
        perl_destruct(my_perl);
        perl_free(my_perl);
PERL_SYS_TERM();
exit(EXIT_SUCCESS);
 }

使用以下任一方法

gcc -o interp interp.c `perl -MExtUtils::Embed -e ccopts -e ldopts`

gcc -O2 -Dbool=char -DHAS_BOOL -I/usr/local/include -I/usr/lib64/perl5/CORE -L/usr/lib64/perl5/CORE -o interp interp.c -lperl -lm

我收到以下错误

--- 切到这里 ---

In file included from /usr/lib64/perl5/CORE/perl.h:3939,
                 from interp.c:2:
/usr/lib64/perl5/CORE/parser.h:17:7: error: redefinition of 'union YYSTYPE'
 union YYSTYPE
       ^~~~~~~
In file included from /usr/lib64/perl5/CORE/perl.h:3899,
                 from interp.c:2:
/usr/lib64/perl5/CORE/perly.h:164:7: note: originally defined here
 union YYSTYPE
       ^~~~~~~
In file included from /usr/lib64/perl5/CORE/perl.h:3939,
                 from interp.c:2:
/usr/lib64/perl5/CORE/parser.h:28:23: error: conflicting types for 'YYSTYPE'
 typedef union YYSTYPE YYSTYPE;
                       ^~~~~~~
In file included from /usr/lib64/perl5/CORE/perl.h:3899,
                 from interp.c:2:
/usr/lib64/perl5/CORE/perly.h:175:23: note: previous declaration of 'YYSTYPE' was here
 typedef union YYSTYPE YYSTYPE;
                       ^~~~~~~

--- 切到这里 ---

我在下面的头文件中对 YYSTYPE 进行了 grep 编辑,但假设我不必更改 perl 发行版提供的标头

$grep -i YYSTYPE /usr/lib64/perl5/CORE/perl.h 没有匹配项

$grep -i YYSTYPE /usr/lib64/perl5/CORE/parser.h

#ifndef YYSTYPE
union YYSTYPE
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
    YYSTYPE val;    /* semantic value */
    YYSTYPE         yylval;     /* value of lookahead symbol, set by yylex() */
    YYSTYPE     nextval[5];     /* value of next token, if any */

$grep -i YYSTYPE /usr/lib64/perl5/CORE/perly.h

#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1

任何人都可以帮我解决这个问题,以便程序能够编译。如果头文件需要更改,那么有没有办法使用我自己的副本并更改它们,而不是与 RHEL 捆绑的文件?

c perl
1个回答
0
投票

显然这是一个错误,已在提交3f5e954中修复。该修复程序编写于 2017 年 11 月 16 日,作为 Perl v5.27.6 的一部分发布。

要么:

  • 升级到 Perl 5.28.0 或更高版本
  • 手动将补丁应用到 /usr/lib64/perl5/CORE/perly.h 的副本。

即将

typedef union YYSTYPE YYSTYPE;
线移至 union YYSTYPE 块上方

diff --git a/perly.h b/perly.h index eb14b421c7..7906ab5eb1 100644 --- a/perly.h +++ b/perly.h @@ -160,7 +160,7 @@ S_is_opval_token(int type) { #endif /* PERL_IN_TOKE_C */ #endif /* PERL_CORE */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED - +typedef union YYSTYPE YYSTYPE; union YYSTYPE { @@ -171,8 +171,6 @@ union YYSTYPE GV *gvval; }; - -typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 #endif -- 2.43.0
    
© www.soinside.com 2019 - 2024. All rights reserved.