H2PH(1perl)
π H2PH β the manual, but make it make sense
okay bestie, gather round, because today we're talking about h2ph, the little utility that lives in the Perl Programmers Reference Guide and does exactly one job: it takes your .h C header files and turns them into .ph Perl header files. that's the whole vibe. it's giving translator, it's giving glow-up, it's giving "i speak both languages actually". π¦
β¨ NAME β¨
h2ph β convert .h C header files to .ph Perl header files π
β¨ SYNOPSIS β¨
h2ph [-d destination directory] [-r | -a] [-l] [-h] [-e] [-D] [-Q]
[headerfiles]
β¨ DESCRIPTION β¨
so here's the tea: h2ph converts any C header files you hand it into the corresponding Perl header file format. iconic behavior. honestly?
the easiest way to run it is from inside /usr/include, like:
cd /usr/include; h2ph * sys/*
or, if you want more:
cd /usr/include; h2ph * sys/* arpa/* netinet/*
or, the full send:
cd /usr/include; h2ph -r -l .
the output files get dropped into the hierarchy rooted at Perl's architecture dependent library directory β that's its home, that's where it lives, that's its main character address. π but if you want a different hierarchy, you just say so with the -d switch. slay, options, we love her.
and if you run it with no arguments at all? it just filters standard input to standard output. no notes. a pipe queen. π
β¨ OPTIONS β¨
-d destination_dirβ put the resulting.phfiles beneath destination_dir instead of beneath the default Perl library location ($Config{'installsitearch'}). moving out, getting a new place, very that. π-rβ run recursively. if any of headerfiles are directories, then runh2phon all files in those directories (and their subdirectories, etc. β down and down and down, it's giving inception). π heads up:-rand-aare mutually exclusive, so you literally cannot have both, pick a lane bestie.-aβ run automagically β¨. convert headerfiles, as well as any.hfiles which they include. this option will search for.hfiles in all directories which your C compiler ordinarily uses. no cap, all of them. and yes:-aand-rare mutually exclusive, same deal as above. π-lβ symbolic links will be replicated in the destination directory. if-lis not specified, then links are skipped over. so either you bring the links with you or you leave them at the door. πͺ-hβ put 'hints' in the.phfiles which will help in locating problems withh2ph. so in those cases when you require a.phfile containing syntax errors, instead of the cryptic
[ some error condition ] at (eval mmm) line nnn
you will see the slightly more helpful
[ some error condition ] at filename.ph line nnn
likeβ¦ actual information?? we love clarity. but plot twist: the .ph files almost double in size when built using -h. π so it's helpful and heavy, choose wisely.
-eβ if an error is encountered during conversion, the output file will be removed and a warning emitted, instead of terminating the conversion immediately. so it keeps going, it doesn't crash out, it just quietly cleans up after itself. resilient queen. π-Dβ include the code from the.hfile as a comment in the.phfile. this is primarily used for debuggingh2ph. receipts, in the file, for later. π-Qβ 'Quiet' mode; don't print out the names of the files being converted. sometimes you just don't need to announce every single thing you're doing. mysterious. π€«
β¨ ENVIRONMENT β¨
literally none. no environment variables are used. nothing to configure, nothing to export, nothing to stress about. a clean slate, a fresh face. πΈ
β¨ FILES β¨
/usr/include/*.h
/usr/include/sys/*.h
etc. β and by "etc." we mean etc., there's more, that's the point. π«Ά
β¨ AUTHOR β¨
Larry Wall π β yes, that Larry Wall. the legend himself.
β¨ SEE ALSO β¨
perl(1) β go read it, bestie, it's the whole universe this little tool lives inside. π
β¨ DIAGNOSTICS β¨
the usual warnings if it can't read or write the files involved. nothing dramatic, nothing mysterious β if it can't touch the file, it's gonna tell you about it. π’
β¨ BUGS β¨
okay so this is the part where we're honest. β
- doesn't construct the
%sizeofarray for you. not its job, apparently. π - it doesn't handle all C constructs, but it does attempt to isolate definitions inside
evalsso that you can get at the definitions that it can translate. so like, partial credit, but the effort is genuinely there. πͺ - it's only intended as a rough tool. you may need to dicker with the files produced. yes, dicker. as in poke at them, adjust them, have a whole conversation with them. π§
- you have to run this program by hand; it's not run as part of the Perl installation. no automation, no cron goblin doing it for you. you, personally, with your own two hands. π
- doesn't handle complicated expressions built piecemeal, a la:
enum {
FIRST_VALUE,
SECOND_VALUE,
#ifdef ABC
THIRD_VALUE
#endif
};
likeβ¦ it said no to that specific situation. π«
- doesn't necessarily locate all of your C compiler's internally-defined symbols. some of them are just out here living their truth, unfound. ππ
and that's the whole page, bestie. this documentation came from the Perl Programmers Reference Guide, straight out of perl v5.44.0, dated 2026-10-17. take care of her, run her from the right directory, and always read the BUGS section before you get mad at a tool. mwah. πβ¨π
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms