Linux command
h2xs 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Create an XS module skeleton without AutoLoader
h2xs -A -n [Module::Name]
Create a module skeleton from a C header file
h2xs -n [Module::Name] [header.h]
Create a pure Perl module (no XS code)
h2xs -AX -n [Module::Name]
Create a module and drop a C function name prefix from Perl bindings
h2xs -n [Module::Name] -p [prefix_] [header.h]
说明
h2xs builds a Perl extension skeleton from C header files. It generates XS code to wrap C libraries, making their constants and functions accessible from Perl, along with a `Makefile.PL`, `.pm` module file, `.xs` file, and test stubs. If no module name is supplied with `-n`, the name of the first header file is used with its first character capitalised. Extra libraries needed at link time can be appended on the command line in the form `-lm -lposix`, optionally with `-L/path` to add a library search directory. The tool can also create a skeleton pure Perl module (no XS) by using the `-X` flag.
参数
- -n, --name=_MODULE_NAME_
- Specify the name for the extension, e.g. `RPC::DCE`. If omitted, the name of the first header file (capitalised) is used.
- -A, --omit-autoload
- Omit all AutoLoader facilities. Removes `use AutoLoader` from the .pm file and implies `-c`.
- -X, --omit-XS
- Omit the XS portion and generate a skeleton pure Perl module. Implies `-c` and `-f`.
- -c, --omit-constant
- Omit `constant()` from the .xs file and the corresponding `AUTOLOAD` from the .pm file.
- -O, --overwrite-ok
- Allow an existing extension directory to be overwritten.
- -b, --compat-version=_VERSION_
- Generate a .pm file backwards-compatible with the specified Perl version (e.g. `5.005_03`). Versions below 5.6.0 avoid `our` and `use warnings`.
- -B, --beta-version
- Use an alpha/beta-style version number (`0.00_01`) instead of `0.01`.
- -C, --omit-changes
- Omit creation of the `Changes` file and add a `HISTORY` section to the POD template instead.
- -F, --cpp-flags=_FLAGS_
- Additional flags to pass to the C preprocessor when scanning headers. Also written into the generated `Makefile.PL`.
- -M, --func-mask=_REGEX_
- Select only functions and macros whose names match the given regular expression.
- -P, --omit-pod
- Omit the autogenerated stub POD section.
- -a, --gen-accessors
- Generate accessor methods for each element of structs and unions found in the header.
- -d, --debugging
- Turn on debugging messages.
- -e, --omit-enums=_REGEX_
- Skip constants defined in C enumerations. If a regex is given, skip only enums whose names match it.
- -f, --force
- Allow creating an extension for a header that is not found in standard include directories.
- -g, --global
- Include code for safely storing static data in the .xs file.
- -k, --omit-const-func
- For function arguments declared as `const`, omit the `const` attribute in the generated XS code.
- -m, --gen-tied-var
- (Experimental) Declare Perl variables magically tied to C variables of the same name.
- -o, --opaque-re=_REGEX_
- Treat C types matched by the regex as opaque data types even if they appear in typemaps. Use with `-x`.
- -p, --remove-prefix=_PREFIX_
- Remove the given prefix from Perl function names (e.g. `-p sec_rgy_`).
- -s, --const-subs=_SUB1_,_SUB2_
- Create Perl subroutines for the specified macros (assumed `char *` return type) rather than using the `constant()` mechanism.
- -t, --default-type=_TYPE_
- Internal type used by `constant()` for macros. Defaults to `IV` (signed integer).
- -v, --version=_VERSION_
- Set the version number for the extension. Defaults to `0.01` (or `0.00_01` with `-B`).
- -x, --autogen-xsubs
- Automatically generate XSUBs from function declarations in the header. Requires the `C::Scan` module.
FAQ
What is the h2xs command used for?
h2xs builds a Perl extension skeleton from C header files. It generates XS code to wrap C libraries, making their constants and functions accessible from Perl, along with a `Makefile.PL`, `.pm` module file, `.xs` file, and test stubs. If no module name is supplied with `-n`, the name of the first header file is used with its first character capitalised. Extra libraries needed at link time can be appended on the command line in the form `-lm -lposix`, optionally with `-L/path` to add a library search directory. The tool can also create a skeleton pure Perl module (no XS) by using the `-X` flag.
How do I run a basic h2xs example?
Run `h2xs -A -n [Module::Name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -n, --name=_MODULE_NAME_ do in h2xs?
Specify the name for the extension, e.g. `RPC::DCE`. If omitted, the name of the first header file (capitalised) is used.