错误:无法解析Mytest.xs第9行中的'hello()'中的函数定义

时间:2010-04-08 18:46:07

标签: perl

我正在尝试在RHEL 5中使用perl XS。 但是简单的程序正在给出错误。我遵循与Example 1 in perldoc perlxstut

中相同的代码

有人可以帮我纠正以下错误吗?

[root@localhost Mytest]# 
[root@localhost Mytest]# pwd
/home/nikole/perlcode/Mytest
[root@localhost Mytest]# ls
blib     lib          MANIFEST  Mytest.xs   pm_to_blib  README
Changes  Makefile.PL  Mytest.c  Mytest.xsc  ppport.h    t
[root@localhost Mytest]# perl Makefile.PL 
Checking if your kit is complete...
Looks good
Writing Makefile for Mytest
[root@localhost Mytest]# 
[root@localhost Mytest]# 
[root@localhost Mytest]# make
/usr/bin/perl /usr/lib/perl5/5.8.8/ExtUtils/xsubpp  -typemap /usr/lib/perl5/5.8.8/ExtUtils/typemap  Mytest.xs > Mytest.xsc && mv Mytest.xsc Mytest.c
Error: Cannot parse function definition from '    hello()' in Mytest.xs, line 9
Please specify prototyping behavior for Mytest.xs (see perlxs manual)
make: *** [Mytest.c] Error 1
[root@localhost Mytest]# 

谢谢Ryan。我删除了voidhello之间的空格,解决了问题。编辑后,我的Mytest.xs看起来像

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "ppport.h"

MODULE = Mytest         PACKAGE = Mytest

void
hello()
CODE:
    printf("Hello, world!\n");

更新

嗨Ryan& CJM, 我解决了上面做的错误,但是我的perl程序现在正在给出错误 “use:command not found”

有什么想法吗?

[root@localhost Mytest]# 
[root@localhost Mytest]# 
[root@localhost Mytest]# perl Makefile.PL 
Checking if your kit is complete...
Looks good
Writing Makefile for Mytest
[root@localhost Mytest]# 
[root@localhost Mytest]# 
[root@localhost Mytest]# make
gcc -c  -I. -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables   -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" -fPIC "-I/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE"   Mytest.c
Running Mkbootstrap for Mytest ()

chmod 644 Mytest.bs

rm -f blib/arch/auto/Mytest/Mytest.so

gcc  -shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -L/usr/local/lib Mytest.o  -o blib/arch/auto/Mytest/Mytest.so    \
                \

chmod 755 blib/arch/auto/Mytest/Mytest.so
cp Mytest.bs blib/arch/auto/Mytest/Mytest.bs
chmod 644 blib/arch/auto/Mytest/Mytest.bs
Manifying blib/man3/Mytest.3pm
[root@localhost Mytest]# 


[root@localhost Mytest]# 
[root@localhost Mytest]# 
[root@localhost Mytest]# cat hello

   #! /usr/bin/perl -w
    use ExtUtils::testlib;
    use Mytest;
    Mytest::hello();


[root@localhost Mytest]# 
[root@localhost Mytest]# cat hello

   #! /usr/bin/perl -w
    use ExtUtils::testlib;
    use Mytest;
    Mytest::hello();


[root@localhost Mytest]# 
[root@localhost Mytest]# ls -l hello 

-rwxrwxrwx 1 root root 87 Apr  8 04:01 hello

[root@localhost Mytest]# 


[root@localhost Mytest]# 
[root@localhost Mytest]# ./hello 

./hello: line 2: use: command not found
./hello: line 3: use: command not found
./hello: line 4: syntax error near unexpected token `;'
./hello: line 4: `    Mytest::hello();'
[root@localhost Mytest]#

更新

谢谢Ryan, 删除了void和hello之间的空格 它解决了问题 编辑后,我的Mytest.xs看起来像

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "ppport.h"

MODULE = Mytest         PACKAGE = Mytest

void

hello()

        CODE:
            printf("Hello, world!\n");

1 个答案:

答案 0 :(得分:2)

在Mytest.xs中删除hello();

前面的空格

<强>更新 您的新问题“未找到命令...”听起来并不像Perl正在运行您的程序。我想它可能来自hello中“#!/ usr / bin / perl”之前的空格。