in reply to Re: own perl module based on c library
in thread own perl module based on c library

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

Replies are listed 'Best First'.
Re^3: own perl module based on c library
by gants (Novice) on Apr 28, 2010 at 13:32 UTC
    #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)'