Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: XS Library - Embedding C code in Perl

by Zaxo (Archbishop)
on Nov 14, 2002 at 00:11 UTC ( #212728=note: print w/ replies, xml ) Need Help??


in reply to XS Library - Embedding C code in Perl

Inline is fine, but it is perhaps not as well integrated into ExtUtils and module building as the standard XS interface.

To answer your question directly, you should #include the perl headers before your C code, unless there is good reason not to. That gives you macros and functions to ease writing your functions . This example is adapted from perlxstut, which I recommend to you:

MODULE = Foo PACKAGE = Foo int is_even(input) int input CODE: RETVAL = (input % 2 == 0); OUTPUT: RETVAL

I'd parse the command line in perl before calling library functions with the arguments.

To link to an external lib, #include <foo.h> (its header) in the xs file, and put the linker directive '-lfoo' in Makefile.PL's LIB parameter.

After Compline,
Zaxo


Comment on Re: XS Library - Embedding C code in Perl
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://212728]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2014-12-23 04:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (135 votes), past polls