When working through perlxstut, I get stuck in example 4. After making all the described file edits, and running h2xs, I get these messages when building the Makefile and making it:
$ perl Makefile.PL MakeMaker (v6.36) Warning (non-fatal): Target 'dynamic' depends on targets in skipped se +ction 'dynamic_lib' Warning (non-fatal): Target 'static' depends on targets in skipped sec +tion 'static_lib' Writing Makefile for Mytest2::mylib Writing Makefile for Mytest2 $ make cp lib/Mytest2.pm blib/lib/Mytest2.pm AutoSplitting blib/lib/Mytest2.pm (blib/lib/auto/Mytest2) mylib/libmylib.a: mylib/Makefile make: mylib/libmylib.a:: Command not found make: *** [pm_to_blib] Error 127
When running make again, the error message changes to
$ make make: *** No rule to make target `mylib/libmylib.a', needed by `subdir +s'. Stop.

I get the same error message if I run 'make perl' instead of 'make'.

Any help would be immensely appreciated. I believe I created all the files correctly, and I'm copying them below.

I tried this on two systems:

SunOS 5.8, with Perl 5.8.8, MakeMaker 6.36 and GNU make 3.80. Perl -V:make is 'make'.

Cygwin with Perl 5.10.0, MakeMaker 6.44, and GNU make 3.81.

Thanks for helping me out!

Bernd.

The relevant section in Mytest2/Makefile is
# --- MakeMaker top_targets section: all :: pure_all manifypods $(NOECHO) $(NOOP) pure_all :: config pm_to_blib subdirs linkext $(NOECHO) $(NOOP) subdirs :: $(MYEXTLIB) $(NOECHO) $(NOOP) config :: $(FIRST_MAKEFILE) blibdirs $(NOECHO) $(NOOP) $(O_FILES): $(H_FILES)

and MYEXTLIB is defined in the same Makefile in the constants section as

MYEXTLIB = mylib/libmylib$(LIB_EXT)

and a rule for it is provided in the postamble section:

# --- MakeMaker postamble section: $(MYEXTLIB): mylib/Makefile cd mylib && $(MAKE) $(PASSTHRU)

The Makefile is created from this 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 mo +dule AUTHOR => 'Bernd Kastenmeier <b01767@am.freescale.net>' +) : ()), LIBS => [''], # e.g., '-lm' DEFINE => '', # e.g., '-DHAVE_SOMETHING' INC => '-I.', # e.g., '-I. -I/usr/include/other' 'MYEXTLIB' => 'mylib/libmylib$(LIB_EXT)', # Un-comment this if you add C files to link with later: # OBJECT => '$(O_FILES)', # link all the C files too ); 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::postamble { ' $(MYEXTLIB): mylib/Makefile cd mylib && $(MAKE) $(PASSTHRU) '; }

The .xs file in the same directory is here:

#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "mylib/mylib.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 <c> <p></p> <p>...and there's also a typemap file in this directory, which only ha +s one line: </p><c> const char * T_PV

Here are the files I created in mylib:

Makefile.PL:
use ExtUtils::MakeMaker; $Verbose = 1; WriteMakefile( NAME => 'Mytest2::mylib', SKIP => [qw(all static static_lib dynamic dynamic_lib)], # clean => {'FILES' => 'libmylib$(LIB_EXT)'}, ); sub MY::top_targets { ' all :: static pure_all :: static static :: libmylib$(LIB_EXT) libmylib$(LIB_EXT): $(O_FILES) $(AR) cr libmylib$(LIB_EXT) $(O_FILES) $(RANLIB) libmylib$(LIB_EXT) '; }
mylib.h:
#define TESTVAL 4 extern double foo(int, long, const char*);
mylib.c:
#include <stdlib.h> #include "./mylib.h" double foo(int a, long b, const char *c) { return (a+b+atof(c) + TESTVAL); }

and here, as requested by syphilis, the file blib.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 expo +rt # 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 @EXP +ORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( TESTVAL ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); 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 p +rogram. 1; __END__

In reply to stuck in perlxstut, example 4 by fugazi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.