Replies: 1 comment 1 reply
-
Hello. You have stumbled into the wrong place to see help for C integrations in Perl. Mojolicious is a pure-perl (ie, non-C) web framework for Perl and not the Perl language itself. You might look for resources here or on say StackOverflow. Hope you find someone to help you out! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Perl Version : 5.26
O/S = RHEL 8.7
Hi, I am new to adding perl into 'C' programs and so am trying to following the examples in 'https://docs.mojolicious.org/perlembed#Adding-a-Perl-interpreter-to-your-C-program' so I can use it in a project I am working on. However, I am hitting issues e.g.
--- cut here ---
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
^~~~~~~
--- cut here ---
(see other similar errors in below section)
The environment I am running on is described below:
$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
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
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
osvers=4.18.0-305.17.1.el8_4.x86_64
archname=x86_64-linux-thread-multi
uname='linux x86-038.build.eng.bos.redhat.com 4.18.0-305.17.1.el8_4.x86_64 #1 smp mon aug 30 07:26:31 edt 2021 x86_64 x86_64 x86_64 gnulinux '
..
..
..
Built under linux
Compiled at Oct 27 2021 03:00:15
%ENV:
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
If I try to compile the interp.c program below
--- cut here ---
#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);
}
--- cut here ---
using either of the following
gcc -o interp interp.c
perl -MExtUtils::Embed -e ccopts -e ldopts
or
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
I get the following errors
--- cut here ---
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;
^~~~~~~
--- cut here ---
I have grep'ed for YYSTYPE in the header files below but assume I should not have to change the headers supplied with the perl distribution
$grep -i YYSTYPE /usr/lib64/perl5/CORE/perl.h
none
$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
$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
Can any one help me with the solution to this please, so that the program will compile.
Beta Was this translation helpful? Give feedback.
All reactions