|
Manpages H2XSSection: Perl Programmers Reference Guide (1)Updated: 2005-03-28 Index Return to Main Contents NAMEh2xs - convert .h C header files to Perl extensionsSYNOPSISh2xs [-ACOPXacdfkmx] [-F addflags] [-M fmask] [-n module_name] [-o tmask] [-p prefix] [-s subs] [-v version] [headerfile ... [extra_libraries]]DESCRIPTIONh2xs builds a Perl extension from C header files. The extension will include functions which can be used to retrieve the value of any #define statement which was in the C header files.The module_name will be used for the name of the extension. If module_name is not supplied then the name of the first header file will be used, with the first character capitalized. If the extension might need extra libraries, they should be included here. The extension Makefile.PL will take care of checking whether the libraries actually exist and how they should be loaded. The extra libraries should be specified in the form -lm -lposix, etc, just as on the cc command line. By default, the Makefile.PL will search through the library path determined by Configure. That path can be augmented by including arguments of the form -L/another/library/path in the extra-libraries argument. OPTIONS
EXAMPLES
# Default behavior, extension is Rusers
h2xs rpcsvc/rusers
# Same, but extension is RUSERS
h2xs -n RUSERS rpcsvc/rusers
# Extension is rpcsvc::rusers. Still finds <rpcsvc/rusers.h>
h2xs rpcsvc::rusers
# Extension is ONC::RPC. Still finds <rpcsvc/rusers.h>
h2xs -n ONC::RPC rpcsvc/rusers
# Without constant() or AUTOLOAD
h2xs -c rpcsvc/rusers
# Creates templates for an extension named RPC
h2xs -cfn RPC
# Extension is ONC::RPC.
h2xs -cfn ONC::RPC
# Makefile.PL will look for library -lrpc in
# additional directory /opt/net/lib
h2xs rpcsvc/rusers -L/opt/net/lib -lrpc
# Extension is DCE::rgynbase
# prefix "sec_rgy_" is dropped from perl function names
h2xs -n DCE::rgynbase -p sec_rgy_ dce/rgynbase
# Extension is DCE::rgynbase
# prefix "sec_rgy_" is dropped from perl function names
# subroutines are created for sec_rgy_wildcard_name and sec_rgy_wildcard_sid
h2xs -n DCE::rgynbase -p sec_rgy_ \
-s sec_rgy_wildcard_name,sec_rgy_wildcard_sid dce/rgynbase
# Make XS without defines in perl.h, but with function declarations
# visible from perl.h. Name of the extension is perl1.
# When scanning perl.h, define -DEXT=extern -DdEXT= -DINIT(x)=
# Extra backslashes below because the string is passed to shell.
# Note that a directory with perl header files would
# be added automatically to include path.
h2xs -xAn perl1 -F "-DEXT=extern -DdEXT= -DINIT\(x\)=" perl.h
# Same with function declaration in proto.h as visible from perl.h.
h2xs -xAn perl2 perl.h,proto.h
# Same but select only functions which match /^av_/
h2xs -M '^av_' -xAn perl2 perl.h,proto.h
# Same but treat SV* etc as "opaque" types
h2xs -o '^[S]V \*$' -M '^av_' -xAn perl2 perl.h,proto.h
Extension based on .h and .c filesSuppose that you have some C files implementing some functionality, and the corresponding header files. How to create an extension which makes this functionality accessable in Perl? The example below assumes that the header files are interface_simple.h and interface_hairy.h, and you want the perl module be named as "Ext::Ension". If you need some preprocessor directives and/or linking with external libraries, see the flags "-F", "-L" and "-l" in ``OPTIONS''.
ENVIRONMENTNo environment variables are used.AUTHORLarry Wall and othersSEE ALSOperl, perlxstut, ExtUtils::MakeMaker, and AutoLoader.DIAGNOSTICSThe usual warnings if it cannot read or write the files involved.LIMITATIONS of -xh2xs would not distinguish whether an argument to a C function which is of the form, say, "int *", is an input, output, or input/output parameter. In particular, argument declarations of the form
int
foo(n)
int *n
should be better rewritten as
int
foo(n)
int &n
if "n" is an input parameter.
Additionally, h2xs has no facilities to intuit that a function
int
foo(addr,l)
char *addr
int l
takes a pair of address and length of data at this address, so it is better
to rewrite this function as
int
foo(sv)
SV *addr
PREINIT:
STRLEN len;
char *s;
CODE:
s = SvPV(sv,len);
RETVAL = foo(s, len);
OUTPUT:
RETVAL
or alternately
static int
my_foo(SV *sv)
{
STRLEN len;
char *s = SvPV(sv,len);
return foo(s, len);
}
MODULE = foo PACKAGE = foo PREFIX = my_
int
foo(sv)
SV *sv
See perlxs and perlxstut for additional details.
Index
This document was created by man2html, using the manual pages. Time: 07:21:15 GMT, December 18, 2025 |