ArthurDent has asked for the wisdom of the Perl Monks concerning the following question:

Howdy fellow monks! I've been fighting with perlxs and a C++ class for a bit now. I've managed to get the whole thing to compile, but I'm having a bit of trouble understanding how to use it now that I've got it. The perldoc for perlxs seems to say how to set up the .xs file, but not how to call the functions. For instance, I've added the following to the basic .xs file:
float Point_2D::x() CODE: RETVAL=THIS->x(); OUTPUT: RETVAL void Point_2D::set_x(arg) float arg CODE: THIS->x(arg); void Point_2D::DESTROY() CODE: delete THIS; Point_2D * Point_2D::new() CODE: RETVAL = new Point_2D(); OUTPUT: RETVAL
And I've made a test script that looks like this:
#!/usr/sbin/perl -w use ExtUtils::testlib; use Point_2D; my $pt; my $output; print "making object\n"; $pt = Point_2D::new(Point_2D); print "setting value\n"; Point_2D::set_x($pt,1.2); print "retrieving value\n"; $output = Point_2D::x($pt); print "output = ",$output;
The output of which is:
making object
12823:/usr/sbin/perl: rld: Fatal Error: attempted access to unresolvable symbol in bli

Replies are listed 'Best First'.
Re: perlxs and C++
by perlmonkey (Hermit) on May 17, 2000 at 11:53 UTC
    I have never made an extension, so I cant answer your question out right.

    I played around with your code, and I read perlman:perlxs and perlman:perlxstut and I did not get very far with C++ coding. It seems that it is all written in C, and there are little or no examples for C++.

    I looked in Advanced Perl Programming and that only briefly mentions C++ also. But the author Sriram Srinivasan mentions other resources on CPAN by Dean Roehrich. Dean has code and extension examples in two cookbooks: CookBookA and CookBookB which you can get here I have not had the chance to look at them but the readme looked promising.

    Good luck. I will post more if I find anything else out.