I want to write Perl bindings for a C++ library, so that the library can be used from Perl. How would I get started doing this? I've written pure-Perl modules for CPAN before.
Asked
Active
Viewed 2,425 times
2 Answers
7
There is SWIG and there XS. I used XS for Net::Sharktools which was the first time I wrote any XS code. I point to it because it was a particularly trivial case, and might be a good way to get an idea of what is involved.
perldoc perlxs includes a section on C++ specific aspects as well.

Sinan Ünür
- 116,958
- 15
- 196
- 339
-
1Make sure to check out xsubpp's -hiertype option when dealing with C++ in XS. – tsee Oct 26 '11 at 06:05
6
Binding a C++ library is a lot trickier that a C library, for a lot of reasons. Not in the last place because the standard toolchain is fairly C centric. XSpp is a lot more powerful that plain XS, though it has an additional learning curve.
I'd love to recommend my own libperl++ for this, but it's still very much in the alpha stage.

Leon Timmermans
- 30,029
- 2
- 61
- 110
-
1What Leon said. For XS++ (XSpp) my slides from YAPC in Pisa may be useful: http://steffen-mueller.net/talks/xspp/ XS++ examples include in order of complexity: Math::ThinPlateSpline, Math::Clipper, Wx – tsee Oct 26 '11 at 06:06
-
Oh, and I forgot to mention 'SOOT' as an example. But that's so weird that anybody learning from it would have to be more than a little insane. :) – tsee Oct 26 '11 at 06:13