Hi
I am trying the example 4 of
http://search.cpan.org/dist/perl/pod....pod#EXAMPLE_4. For perl XS in RHEL 5.
but i am getting this error
[root@localhost Mytest2]# cat Makefile.PL
use 5.008008;
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
NAME => 'Mytest2',
VERSION_FROM => 'lib/Mytest2.pm', # finds $VERSION
PREREQ_PM => {}, # e.g., Module::Name => 1.1
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'lib/Mytest2.pm', # retrieve abstract from module
AUTHOR => 'nikole <root@localdomain>') : ()),
LIBS => [''], # e.g., '-lm'
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
INC => '-I.', # e.g., '-I. -I/usr/include/other'
MYEXTLIB => 'mylib/libmylib$(LIB_EXT)',
);
if (eval {require ExtUtils::Constant; 1}) {
# If you edit these definitions to change the constants used by this module,
# you will need to use the generated const-c.inc and const-xs.inc
# files to replace their "fallback" counterparts before distributing your
# changes.
my @names = (qw(TESTVAL));
ExtUtils::Constant::WriteConstants(
NAME => 'Mytest2',
NAMES => \@names,
DEFAULT_TYPE => 'IV',
C_FILE => 'const-c.inc',
XS_FILE => 'const-xs.inc',
);
}
else {
use File::Copy;
use File::Spec;
foreach my $file ('const-c.inc', 'const-xs.inc') {
my $fallback = File::Spec->catfile('fallback', $file);
copy ($fallback, $file) or die "Can't copy $fallback to $file: $!";
}
}
sub MY:
ostamble {
'
$(MYEXTLIB): mylib/Makefile
cd mylib && $(MAKE) $(PASSTHRU)
';
}
[root@localhost Mytest2]#
[root@localhost Mytest2]# ls
Changes fallback lib Makefile.PL MANIFEST mylib Mytest2.xs ppport.h README t typemap
[root@localhost Mytest2]# cat t/Mytest2.t
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Mytest2.t'
#########################
# change 'tests => 2' to 'tests => last_test_to_print';
use Test::More tests => 2;
BEGIN { use_ok('Mytest2') };
my $fail = 0;
foreach my $constname (qw(
TESTVAL)) {
next if (eval "my \$a = $constname; 1");
if ($@ =~ /^Your vendor has not defined Mytest2 macro $constname/) {
print "# pass: $@";
} else {
print "# fail: $@";
$fail = 1;
}
}
ok( $fail == 0 , 'Constants' );
#########################
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.
[root@localhost Mytest2]#
[root@localhost Mytest2]# cat Mytest2.xs
#include "mylib/mylib.h"
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include <./Mytest2/mylib/mylib.h>
#include "const-c.inc"
MODULE = Mytest2 PACKAGE = Mytest2
INCLUDE: const-xs.inc
double
foo(a,b,c)
int a
long b
const char * c
OUTPUT:
RETVAL
[root@localhost Mytest2]#
[root@localhost Mytest2]#
[root@localhost Mytest2]# cat lib/Mytest2.pm
package Mytest2;
use 5.008008;
use strict;
use warnings;
use Carp;
require Exporter;
use AutoLoader;
our @ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use Mytest2 ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = ( 'all' => [ qw(
TESTVAL
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
#our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} }, qw(
# TESTVAL
#) );
our @EXPORT = qw(
TESTVAL
);
our $VERSION = '0.01';
sub AUTOLOAD {
# This AUTOLOAD is used to 'autoload' constants from the constant()
# XS function.
my $constname;
our $AUTOLOAD;
($constname = $AUTOLOAD) =~ s/.*:://;
croak "&Mytest2::constant not defined" if $constname eq 'constant';
my ($error, $val) = constant($constname);
if ($error) { croak $error; }
{
no strict 'refs';
# Fixed between 5.005_53 and 5.005_61
#XXX if ($] >= 5.00561) {
#XXX *$AUTOLOAD = sub () { $val };
#XXX }
#XXX else {
*$AUTOLOAD = sub { $val };
#XXX }
}
goto &$AUTOLOAD;
}
require XSLoader;
XSLoader::load('Mytest2', $VERSION);
# Preloaded methods go here.
# Autoload methods go after =cut, and are processed by the autosplit program.
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
Mytest2 - Perl extension for blah blah blah
=head1 SYNOPSIS
use Mytest2;
blah blah blah
=head1 DESCRIPTION
Stub documentation for Mytest2, created by h2xs. It looks like the
author of the extension was negligent enough to leave the stub
unedited.
Blah blah blah.
=head2 EXPORT
None by default.
=head2 Exportable constants
TESTVAL
=head1 SEE ALSO
Mention other useful documentation such as the documentation of
related modules or operating system documentation (such as man pages
in UNIX), or any relevant external documentation such as RFCs or
standards.
If you have a mailing list set up for your module, mention it here.
If you have a web site set up for your module, mention it here.
=head1 AUTHOR
nikole, E<lt>root@localdomainE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2010 by nikole
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.8 or,
at your option, any later version of Perl 5 you may have available.
=cut
[root@localhost Mytest2]#
[root@localhost Mytest2]# perl Makefile.PL
Checking if your kit is complete...
Looks good
Bareword found where operator expected at ./Makefile.PL line 10, near "all ::"
(Do you need to predeclare all?)
Bareword found where operator expected at ./Makefile.PL line 12, near "pure_all ::"
(Do you need to predeclare pure_all?)
Bareword found where operator expected at ./Makefile.PL line 14, near "static ::"
(Do you need to predeclare static?)
Bareword found where operator expected at ./Makefile.PL line 14, near "$(LIB_EXT"
(Missing operator before LIB_EXT?)
Semicolon seems to be missing at ./Makefile.PL line 15.
Bareword found where operator expected at ./Makefile.PL line 16, near "$(LIB_EXT"
(Missing operator before LIB_EXT?)
Bareword found where operator expected at ./Makefile.PL line 16, near "$(O_FILES"
(Missing operator before O_FILES?)
Scalar found where operator expected at ./Makefile.PL line 17, near ")
$("
(Missing operator before $(?)
Bareword found where operator expected at ./Makefile.PL line 17, near "$(AR"
(Missing operator before AR?)
Bareword found where operator expected at ./Makefile.PL line 17, near ") cr"
(Missing operator before cr?)
Bareword found where operator expected at ./Makefile.PL line 17, near "$(LIB_EXT"
(Missing operator before LIB_EXT?)
Scalar found where operator expected at ./Makefile.PL line 17, near ") $("
(Missing operator before $(?)
Bareword found where operator expected at ./Makefile.PL line 17, near "$(O_FILES"
(Missing operator before O_FILES?)
Scalar found where operator expected at ./Makefile.PL line 18, near ")
$("
(Missing operator before $(?)
Bareword found where operator expected at ./Makefile.PL line 18, near "$(RANLIB"
(Missing operator before RANLIB?)
Bareword found where operator expected at ./Makefile.PL line 18, near ") libmylib"
(Missing operator before libmylib?)
Bareword found where operator expected at ./Makefile.PL line 18, near "$(LIB_EXT"
(Missing operator before LIB_EXT?)
String found where operator expected at ./Makefile.PL line 20, at end of line
(Missing semicolon on previous line?)
ERROR from evaluation of /home/nikole/perlcode/Mytest2/mylib/Makefile.PL: Can't find string terminator "'" anywhere before EOF at ./Makefile.PL line 20.
[root@localhost Mytest2]#
Does anyone have idea abt this ??