LinuxCommandLibrary

h2xs

Convert C header files into Perl extensions

SYNOPSIS

h2xs [OPTIONS] [headerfile ...]

PARAMETERS

-A
    omit all autoload facilities

-C
    omit C++-ish features like classes

-D
    omit descriptions from generated POD

-F
    force overwriting existing files

-O
    overwrite files without prompting

-X
    generate XS++ code (C++)

-a
    generate AUTOLOAD for constants

-c
    omit constant generation

-d
    generate debug info in XS

-f
    force; skip warnings

-k podname
    name of main POD file

-l
    make module portable (no paths)

-m
    generate Makefile.PL

-n name
    name of generated module

-o outfile
    output file for constants

-p prefix
    prefix for functions/constants

-v
    verbose output

-x
    extra debugging

DESCRIPTION

h2xs is a Perl utility that creates skeleton modules for XS (eXtended Specialty) extensions, converting C header files into Perl bindings.

It parses headers to extract constants, enums, structs, typedefs, and function prototypes, then generates boilerplate files including .pm (Perl module), .xs (XS code), Makefile.PL, typemaps, POD documentation, and tests.

This automates much of the tedious work for interfacing C libraries with Perl, producing a working module framework that developers can customize. For example, h2xs curses.h creates a module binding the curses library.

h2xs supports features like AUTOLOAD for constants, C++ compatibility, and custom naming. It's especially useful for wrapping system libraries or third-party C APIs into reusable Perl modules, speeding up development of high-performance extensions.

CAVEATS

Deprecated in modern Perl; prefer ExtUtils::ParseXS or Module::Build. May fail on complex headers with macros or inline functions. Not suitable for large APIs without manual tweaks.
Removed from Perl core after 5.22; install via perl5.22-legacy-dev or similar.

GENERATED FILES

Typically creates: Module.pm, Module.xs, typemap, Makefile.PL, Module.pod, t/Module.t, Changes.

EXAMPLE

h2xs -O -n Foo::Bar /usr/include/foo.h
Generates Foo/Bar module directory with all files.

HISTORY

Introduced in Perl 5.003 (1996) as part of core dev tools. Evolved through Perl 5.x releases, adding C++ support (-X in 5.6). Marked legacy around Perl 5.14+ with rise of CPAN tools like Dist::Zilla and Inline::C. Dropped from core in Perl 5.22 (2015), now external.

SEE ALSO

xsubpp(1), perlxstut(1), ExtUtils::MakeMaker(3), h2xs(1)

Copied to clipboard