I want to write a shared C library to be used from Perl. In a desperate attempt to figure h2xs out, I have written the following:
// libtwintree.h: int return_one( void ); int return_zero( void );
// libtwintree.c: #include "libtwintree.h" int return_one( void ) { return 1; } int return_zero( void ) { return 0; }
Obviously these are just placeholders for the real functions that this library will implement, it's just that before I write tons of code I really need to get the h2xs monster to cooperate. Anyway, here's the Makefile I'm using to try and fit the pieces together:
TwinTree.pm : TwinTree.xs cd TwinTree && \ perl Makefile.PL && \ make && \ make test && \ make install TwinTree.xs : libtwintree.so install mkdir -p TwinTree && \ cp libtwintree.h TwinTree && \ h2xs -Oxan TwinTree -L/usr/local/lib -llibtwintree libtwintree +.h libtwintree.so : libtwintree.o gcc -shared -Wl,-soname,libtwintree.so -o libtwintree.so libtw +intree.o -lc libtwintree.o : gcc -fPIC -g -c -Wall libtwintree.c clean : rm -Rf *.o *.so TwinTree install : libtwintree.so cp libtwintree.so /usr/local/lib && \ ldconfig -n /usr/local/lib
According to the h2xs manpage, the -x switch is supposed to "Automatically generate XSUBs basing on function declarations in the header file". So... why is it that the generated TwinTree.xs looks like this?
#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include "const-c.inc" MODULE = TwinTree PACKAGE = TwinTree INCLUDE: const-xs.inc
No XSUBs, the entire module is basically 500K of absolutely nothing. What am I missing that's so obvious nobody seems to think it's worth mentioning in the manpage?

Not that I think it matters, but I'm running perl 5.8.8 and uname -a is Linux atlas.atc.no 2.6.27-briullov.1 #1 SMP Fri Apr 3 19:34:58 MSD 2009 i686 i686 i386 GNU/Linux.

Edit: pasted the proper contents of twintree.c

-- Time flies when you don't know what you're doing

In reply to Why does the h2xs -x switch not generate XSUBs? by FloydATC

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.