10

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.

Andreas
  • 7,470
  • 10
  • 51
  • 73
  • 1
    [Swig++](http://www.swig.org/Doc1.3/SWIGPlus.html) comes to mind – sehe Oct 25 '11 at 11:45
  • 1
    Last time I tried it, Swig generated such horrific code that I'm permanently scarred from looking at it. – tsee Oct 26 '11 at 06:04

2 Answers2

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
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
  • 1
    What 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