in reply to own perl module based on c library

have you copied factorial.c and factorial.h into the directory created by h2xs?

It seems that h2xs is not able to generate the XS declarations for the functions in factorial.c

That's what it produces in my machine:

#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" MODULE = Book::Factorial PACKAGE = Book::Factorial

Replies are listed 'Best First'.
Re^2: own perl module based on c library
by almut (Canon) on Apr 27, 2010 at 13:49 UTC

    Looks like the problem is the -F option to h2xs.  Not only is it useless here (which is why I dropped it), it's in fact the source of the problem, because it declares "factorial.h" to be a C preprocessor flag, so there remains no .h file to scan...

    $ h2xs -n Book::Factorial -A -O -x -F factorial.h Defaulting to backwards compatibility with perl 5.10.1 If you intend this module to be compatible with earlier perl versions, + please specify a minimum perl version with the -b option. Writing Book-Factorial/ppport.h Scanning typemaps... Scanning /usr/local/perl/5.10.1/lib/5.10.1/ExtUtils/typemap Writing Book-Factorial/lib/Book/Factorial.pm Writing Book-Factorial/Factorial.xs Writing Book-Factorial/Makefile.PL Writing Book-Factorial/README Writing Book-Factorial/t/Book-Factorial.t Writing Book-Factorial/Changes Writing Book-Factorial/MANIFEST ---- $ h2xs -n Book::Factorial -A -O -x factorial.h Defaulting to backwards compatibility with perl 5.10.1 If you intend this module to be compatible with earlier perl versions, + please specify a minimum perl version with the -b option. Writing Book-Factorial/ppport.h Scanning typemaps... Scanning /usr/local/perl/5.10.1/lib/5.10.1/ExtUtils/typemap Scanning factorial.h for functions... # <--- !! Scanning factorial.h for typedefs... Writing Book-Factorial/lib/Book/Factorial.pm Writing Book-Factorial/Factorial.xs Writing Book-Factorial/Makefile.PL Writing Book-Factorial/README Writing Book-Factorial/t/Book-Factorial.t Writing Book-Factorial/Changes Writing Book-Factorial/MANIFEST

    The latter variant produces the follwing correct Factorial.xs file:

    #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include <factorial.h> MODULE = Book::Factorial PACKAGE = Book::Factorial double factorial_iterative_c(x) int x double factorial_recursive_c(x) int x
      #include <stdio.h> int tst(int len,char str[1024]){ printf("called c from perl len:'%i' str:'%s' \n",len, str); return 1; } int main( ){ tst(54,"char"); return 1; }
      then what's wrong here, in C it works well, module for perl compiled well, but this
      use TST; TST::test(4444,"ss");
      prints called c from perl len:'4444'  str:'(null)'