Linux "h2xs" Command Line Options and Examples
convert .h C header files to Perl extensions

h2xs 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.


Usage:

h2xs [OPTIONS ...] [headerfile ... [extra_libraries]]


    h2xs -h|-?|--help




Command Line Options:

-A
Omit all autoload facilities. This is the same as -c but also removes the "use AutoLoader" statement from the .pm file.
h2xs -A ...
-B
Use an alpha/beta style version number. Causes version number to be "0.00_01" unless -v is specified.
h2xs -B ...
-C
Omits creation of the Changes file, and adds a HISTORY section to the POD template.
h2xs -C ...
-F
Additional flags to specify to C preprocessor when scanning header for function declarations. Writes these options in thegenerated Makefile.PL too.
h2xs -F ...
-M
selects functions/macros to process.
h2xs -M ...
-O
Allows a pre-existing extension directory to be overwritten.
h2xs -O ...
-P
Omit the autogenerated stub POD section.
h2xs -P ...
-X
Omit the XS portion. Used to generate a skeleton pure Perl module. "-c" and "-f" are implicitly enabled.
h2xs -X ...
-a
Generate an accessor method for each element of structs and unions. The generated methods are named after the element name; willreturn the current value of the element if called without additional arguments; and will set the element to the supplied value(and return the new value) if called with an additional argument. Embedded structures and unions are returned as a pointerrather than the complete structure, to facilitate chained calls.These methods all apply to the Ptr type for the structure; additionally two methods are constructed for the structure typeitself, "_to_ptr" which returns a Ptr type pointing to the same structure, and a "new" method to construct and return a newstructure, initialised to zeroes.
h2xs -a ...
-b
Generates a .pm file which is backwards compatible with the specified perl version.For versions < 5.6.0, the changes are.
h2xs -b ...
-
no use of 'our' (uses 'use vars' instead)
h2xs - ...
-c
Omit "constant()" from the .xs file and corresponding specialised "AUTOLOAD" from the .pm file.
h2xs -c ...
-d
Turn on debugging messages.
h2xs -d ...
-e
If regular expression is not given, skip all constants that are defined in a C enumeration. Otherwise skip only those constantsthat are defined in an enum whose name matches regular expression.Since regular expression is optional, make sure that this switch is followed by at least one other switch if you omit regularexpression and have some pending arguments such as header-file names. This is ok:h2xs -e -n Module::Foo foo.hThis is not ok:h2xs -n Module::Foo -e foo.hIn the latter, foo.h is taken as regular expression.
h2xs -e ...
-f
Allows an extension to be created for a header even if that header is not found in standard include directories.
h2xs -f ...
-g
Include code for safely storing static data in the .xs file. Extensions that do no make use of static data can ignore thisoption.
h2xs -g ...
-h
Print the usage, help and version for this h2xs and exit.
h2xs -h ...
-k
For function arguments declared as "const", omit the const attribute in the generated XS code.
h2xs -k ...
-m
Experimental: for each variable declared in the header file(s), declare a perl variable of the same name magically tied to the Cvariable.
h2xs -m ...
-n
Specifies a name to be used for the extension, e.g., -n RPC::DCE
h2xs -n ...
-o
Use "opaque" data type for the C types matched by the regular expression, even if these types are "typedef"-equivalent to typesfrom typemaps. Should not be used without -x.This may be useful since, say, types which are "typedef"-equivalent to integers may represent OS-related handles, and one maywant to work with these handles in OO-way, as in "$handle->do_something()". Use "-o ." if you want to handle all the"typedef"ed types as opaque types.The type-to-match is whitewashed (except for commas, which have no whitespace before them, and multiple "*" which have nowhitespace between them).
h2xs -o ...
-p
Specify a prefix which should be removed from the Perl function names, e.g., -p sec_rgy_ This sets up the XS PREFIX keyword andremoves the prefix from functions that are autoloaded via the "constant()" mechanism.
h2xs -p ...
-s
Create a perl subroutine for the specified macros rather than autoload with the constant() subroutine. These macros are assumedto have a return type of char *, e.g., -s sec_rgy_wildcard_name,sec_rgy_wildcard_sid.
h2xs -s ...
-t
Specify the internal type that the constant() mechanism uses for macros. The default is IV (signed integer). Currently allmacros found during the header scanning process will be assumed to have this type. Future versions of "h2xs" may gain theability to make educated guesses.
h2xs -t ...
--use-new-tests
When --compat-version (-b) is present the generated tests will use "Test::More" rather than "Test" which is the default forversions before 5.6.2. "Test::More" will be added to PREREQ_PM in the generated "Makefile.PL".
h2xs --use-new-tests ...
--use-old-tests
Will force the generation of test code that uses the older "Test" module.
h2xs --use-old-tests ...
--skip-exporter
Do not use "Exporter" and/or export any symbol.
h2xs --skip-exporter ...
--skip-ppport
Do not use "Devel::PPPort": no portability to older version.
h2xs --skip-ppport ...
--skip-autoloader
Do not use the module "AutoLoader"; but keep the constant() function and "sub AUTOLOAD" for constants.
h2xs --skip-autoloader ...
--skip-strict
Do not use the pragma "strict".
h2xs --skip-strict ...
--skip-warnings
Do not use the pragma "warnings".
h2xs --skip-warnings ...
-v
Specify a version number for this extension. This version number is added to the templates. The default is 0.01, or 0.00_01 if
h2xs -v ...
-B"
is specified. The version specified should be numeric.
h2xs -B" ...
-x
Automatically generate XSUBs basing on function declarations in the header file. The package "C::Scan" should be installed. Ifthis option is specified, the name of the header file may look like "NAME1,NAME2". In this case NAME1 is used instead of thespecified string, but XSUBs are emitted only for the declarations included from file NAME2.Note that some types of arguments/return-values for functions may result in XSUB-declarations/typemap-entries which need hand-editing. Such may be objects which cannot be converted from/to a pointer (like "long long"), pointers to functions, or arrays.See also the section on "LIMITATIONS of -x".EXAMPLES# Default behavior, extension is Rusersh2xs rpcsvc/rusers# Same, but extension is RUSERSh2xs -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 AUTOLOADh2xs -c rpcsvc/rusers# Creates templates for an extension named RPCh2xs -cfn RPC# Extension is ONC::RPC.h2xs -cfn ONC::RPC# Extension is a pure Perl module with no XS code.h2xs -X My::Module# Extension is Lib::Foo which works at least with Perl5.005_03.# Constants are created for all #defines and enums h2xs can find# in foo.h.h2xs -b 5.5.3 -n Lib::Foo foo.h# Extension is Lib::Foo which works at least with Perl5.005_03.# Constants are created for all #defines but only for enums# whose names do not start with 'bar_'.h2xs -b 5.5.3 -e '^bar_' -n Lib::Foo foo.h# Makefile.PL will look for library -lrpc in# additional directory /opt/net/libh2xs rpcsvc/rusers -L/opt/net/lib -lrpc# Extension is DCE::rgynbase# prefix "sec_rgy_" is dropped from perl function namesh2xs -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_sidh2xs -n DCE::rgynbase -p sec_rgy_ \
h2xs -x ...