Here's the class declaration from the myclass.h file:cc -c -O -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" -Kpic -I/usr/ +local/lib/ perl5/sun4-solaris/5.00405/CORE myclass.c "/home/judyf/perlwork/myclass/myclass.h", line 9: undefined or not a t +ype: class "/home/judyf/perlwork/myclass/myclass.h", line 9: syntax error before +or at: col or "/home/judyf/perlwork/myclass/myclass.h", line 9: undefined or not a t +ype: color "/home/judyf/perlwork/myclass/myclass.h", line 15: syntax error before + or at: / "/home/judyf/perlwork/myclass/myclass.h", line 23: syntax error before + or at: in t "/home/judyf/perlwork/myclass/myclass.h", line 24: cannot recover from + previous errors cc: acomp failed for myclass.c *** Error code 2 make: Fatal error: Command failed for target `myclass.o'
Here's the relevant .xs code:class color { public: color(); ~color(); int blue(); int set_blue( int ); private: int c_blue; };
My instinct would be, in the myclass.xs file, to create a new package within the one module (called "color") but based on the reference manual doc, I refrained from doing this and kept the class method declaration under the one package (with same name as module). hence, in myclass.xs:int color::blue() void color::set_blue( val ) int val
Here's the relevant portion of typemap file:MODULE = myclass PACKAGE = myclass
Here's Makefile.PL (where I set 'XSOPT' to tell it I'm using C++):color * O_OBJECT OUTPUT # The Perl object is blessed into 'CLASS', which should be a # char* having the name of the package for the blessing. O_OBJECT sv_setref_pv( $arg, CLASS, (void*)$var ); INPUT O_OBJECT if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) ) $var = ($type)SvIV((SV*)SvRV( $arg )); else{ warn( \"${Package}::$func_name() -- $var is not a bles +sed SV ref erence\" ); XSRETURN_UNDEF; }
Thanks for your help.use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'myclass', 'VERSION_FROM' => 'myclass.pm', # finds $VERSION 'LIBS' => [''], # e.g., '-lm' 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' 'INC' => '', # e.g., '-I/usr/include/other' 'XSOPT' => '-C++', );
In reply to using XS with C++ by juda
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |