gpt4 book ai didi

c++ - Perl 5.14 源代码 - 示例程序失败

转载 作者:太空狗 更新时间:2023-10-29 21:49:22 24 4
gpt4 key购买 nike

Perl 5.14 源代码 - 示例程序失败

我正在尝试在 Linux 64 上使用 libperl.so 构建的 5.14 源代码执行以下程序我正在该位置中止

Program terminated with signal 11, Segmentation fault.
#0 0x00002abdc0eb2656 in Perl_sv_2mortal () from ./libperl.so
(gdb) where
#0 0x00002abdc0eb2656 in Perl_sv_2mortal () from ./libperl.so
#1 0x00000000004010ed in PerlPower ()
#2 0x0000000000401335 in main ()
(gdb)

我的程序:

#include <EXTERN.h>
#include <perl.h>
#include <stdio.h>

static PerlInterpreter *my_perl;
static void PerlPower(int a, int b)
{
dSP; /* initialize stack pointer */
ENTER; /* everything created after here */
SAVETMPS; /* ...is a temporary variable. */
PUSHMARK(SP); /* remember the stack pointer */
XPUSHs(sv_2mortal(newSViv(a))); /* push the base onto the stack */
XPUSHs(sv_2mortal(newSViv(b))); /* push the exponent onto stack */
PUTBACK; /* make local stack pointer global */
call_pv("expo", G_SCALAR); /* call the function */
SPAGAIN; /* refresh stack pointer *
/* pop the return value from stack */
printf("%d to the %dth power is %d.\n", a, b, POPi);
PUTBACK;
FREETMPS; /* free that return value */
LEAVE; /* ...and the XPUSHed "mortal" args. */
}

int main(int argc, char **argv, char **env)
{
char *my_argv[] = { "", "power.pl" };

PERL_SYS_INIT3(&argc, &argv, &env);
my_perl = perl_alloc();
perl_construct(my_perl);

perl_parse(my_perl, NULL, 2, my_argv, (char **)NULL);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
perl_run(my_perl);

PerlPower(3, 4);
/*** Compute 3 ** 4 ***/

perl_destruct(my_perl);
perl_free(my_perl);
PERL_SYS_TERM();
}

power.pl 包含以下语句

sub expo {
my ($a, $b) = @_;
return $a ** $b;
}

上面的示例 C 和 perl 程序取自链接 http://perldoc.perl.org/perlembed.html#Evaluating-a-Perl-statement-from-your-C-program

我正在使用以下编译器选项

编译器:

cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -pipe',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement'
ccversion='', gccversion='4.1.2 20070115 (prerelease) (SUSE Linux)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define

你能帮我缩小问题范围吗?

最佳答案

我也有一个,我有 win32 等效的 错误应用程序 power.exe,版本 0.0.0.0,错误模块 perl514.dll,版本 0.0.0.0,错误地址 0x000c155f。但我也收到一条错误消息:)

$ power.exe
Can't open perl script "power.pl": No such file or directory

从嵌入中复制​​ power.pl 后,它按预期工作

$ cat power.pl
sub expo {
my ($a, $b) = @_;
return $a ** $b;
}

$ power.exe
3 to the 4th power is 81.

关于c++ - Perl 5.14 源代码 - 示例程序失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8396480/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com