James Shirley
2011-04-09 06:25:05 UTC
--20cf3071cf6c40d4cb04a07667df
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
Hi, I'm trying to write a XS routine to return a point to a c++ class to be
accessible from perl..
I'm new to XS, so i've been following:
http://www.johnkeiser.com/perl-xs-c++.html
and
http://search.cpan.org/~dmr/CookBookB-19960430/
However when I try make the xs generated code, i get the following compiler
error:
g++ -c -I. -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=3D64 -O2 -g -DVERSION=3D\"0.01\" -DXS_VERSION=3D\"0.0=
1\"
-fPIC "-I/usr/lib/perl/5.10/CORE" MyPackage.c
MyPackage.c: In function =91void XS_MyPackage_child(PerlInterpreter*, CV*)=
=92:
MyPackage.c:168: error: =91CLASS=92 was not declared in this scope
make: *** [MyPackage.o] Error 1
I assume I'm doing something wrong in the child method, however i lifted
this code out of one of the CookBookB examples..
MyClass *
MyClass::child()
CODE:
RETVAL =3D (MyClass *)safemalloc( sizeof(MyClass) );
*RETVAL =3D THIS->child();
OUTPUT:
RETVAL
CLEANUP:
safefree(RETVAL);
Any help would be much appreciated.
I have the following code:
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif
#undef list
#include <iostream>
class MyClass;
class MyClass {
private:
int _id;
public:
MyClass(int id) {
_id =3D id;
}
~MyClass() { }
void operator =3D(const MyClass &other) {
_id =3D other._id;
}
int id() {
return _id;
}
MyClass child() {
return MyClass(5);
}
};
MODULE =3D MyPackage PACKAGE =3D MyPackage
MyClass *
MyClass::new(int id)
void
MyClass::DESTROY()
MyClass *
MyClass::child()
CODE:
RETVAL =3D (MyClass *)safemalloc( sizeof(MyClass) );
*RETVAL =3D THIS->child();
OUTPUT:
RETVAL
CLEANUP:
safefree(RETVAL);
With the Makefile.PL:
use 5.010001;
use ExtUtils::MakeMaker;
$CC =3D 'g++';
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
NAME =3D> 'MyPackage',
VERSION_FROM =3D> 'lib/MyPackage.pm', # finds $VERSION
PREREQ_PM =3D> {}, # e.g., Module::Name =3D> 1.1
($] >=3D 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM =3D> 'lib/MyPackage.pm', # retrieve abstract from mod=
ule
AUTHOR =3D> 'James <james@>') : ()),
LIBS =3D> [''], # e.g., '-lm'
DEFINE =3D> '', # e.g., '-DHAVE_SOMETHING'
INC =3D> '-I.', # e.g., '-I. -I/usr/include/other'
CC =3D> $CC,
LD =3D> '$(CC)',
XSOPT =3D> '-C++',
TYPEMAPS =3D> ['perlobject.map' ],
# Un-comment this if you add C files to link with later:
# OBJECT =3D> '$(O_FILES)', # link all the C files too
);
and the typemap:
TYPEMAP
MyClass * O_OBJECT
Cheers James
--20cf3071cf6c40d4cb04a07667df
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
Hi, I'm trying to write a XS routine to return a point to a c++ class t=
o be accessible from perl..<br><br>I'm new to XS, so i've been foll=
owing:<br><br><a href=3D"http://www.johnkeiser.com/perl-xs-c++.html">http:/=
/www.johnkeiser.com/perl-xs-c++.html</a><br>
<br>and<br><br><a href=3D"http://search.cpan.org/~dmr/CookBookB-19960430/">=
http://search.cpan.org/~dmr/CookBookB-19960430/</a><br><br>However when I t=
ry make the xs generated code, i get the following compiler error:<br><br>
g++ -c=A0 -I. -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pip=
e -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET=
_BITS=3D64 -O2 -g=A0=A0 -DVERSION=3D\"0.01\" -DXS_VERSION=3D\&quo=
t;0.01\" -fPIC "-I/usr/lib/perl/5.10/CORE"=A0=A0 MyPackage.c=
<br>
MyPackage.c: In function =91void XS_MyPackage_child(PerlInterpreter*, CV*)=
=92:<br>MyPackage.c:168: error: =91CLASS=92 was not declared in this scope<=
br>make: *** [MyPackage.o] Error 1<br><br>I assume I'm doing something =
wrong in the child method, however i lifted this code out of one of the Coo=
kBookB examples..<br>
<br>MyClass *<br>
MyClass::child()<br>
=A0 CODE:<br>
=A0=A0=A0 RETVAL =3D (MyClass *)safemalloc( sizeof(MyClass) );<br>
=A0=A0=A0 *RETVAL =3D THIS->child();<br>
<br>
=A0 OUTPUT:<br>
=A0=A0=A0 RETVAL<br>
<br>
=A0 CLEANUP:<br>
=A0=A0=A0 safefree(RETVAL);<br><br>Any help would be much appreciated.<br><=
br>I have the following code:<br><br>#include "EXTERN.h"<br>#incl=
ude "perl.h"<br>#include "XSUB.h"<br><br>#include "=
;ppport.h"<br>
<br>#ifdef __cplusplus<br>=A0 extern "C" {<br>#endif<br>=A0=A0=A0=
#include "EXTERN.h"<br>=A0=A0=A0 #include "perl.h"<br>=
=A0=A0=A0 #include "XSUB.h"<br>#ifdef __cplusplus<br>=A0 }<br>#en=
dif<br><br>#undef list<br> <br>#include <iostream><br><br>class MyClass;<br><br>class MyClass {<=
br>=A0 private:<br>=A0=A0=A0 int _id;<br><br>=A0 public:<br>=A0=A0=A0 MyCla=
ss(int id) {<br>=A0=A0=A0=A0=A0 _id =3D id;<br>=A0=A0=A0 }<br>=A0=A0=A0 <br=
=A0=A0=A0=A0=A0 _id =3D other._id;<br>=A0=A0=A0 }<br><br>=A0=A0=A0 int id()=
{<br>=A0=A0=A0=A0=A0 return _id;<br>=A0=A0=A0 }<br><br>=A0=A0=A0 MyClass c=
hild() {<br>=A0=A0=A0=A0=A0 return MyClass(5);<br>=A0=A0=A0 }<br>};<br><br>=
MODULE =3D MyPackage=A0=A0=A0 PACKAGE =3D MyPackage<br><br>MyClass *<br>
MyClass::new(int id)<br><br>void<br>MyClass::DESTROY()<br><br>MyClass *<br>=
MyClass::child()<br>=A0 CODE:<br>=A0=A0=A0 RETVAL =3D (MyClass *)safemalloc=
( sizeof(MyClass) );<br>=A0=A0=A0 *RETVAL =3D THIS->child();<br><br>=A0 =
OUTPUT:<br>=A0=A0=A0 RETVAL<br>
<br>=A0 CLEANUP:<br>=A0=A0=A0 safefree(RETVAL);<br><br>With the Makefile.PL=
:<br><br>use 5.010001;<br>use ExtUtils::MakeMaker;<br><br>$CC =3D 'g++&=
#39;;<br># See lib/ExtUtils/MakeMaker.pm for details of how to influence<br=
> 'MyPackage',<br>=A0=A0=A0 VERSION_FROM=A0=A0=A0=A0=A0 =3D> =
'lib/MyPackage.pm', # finds $VERSION<br>=A0=A0=A0 PREREQ_PM=A0=A0=
=A0=A0=A0=A0=A0=A0 =3D> {}, # e.g., Module::Name =3D> 1.1<br>=A0=A0=
=A0 ($] >=3D 5.005 ?=A0=A0=A0=A0 ## Add these new keywords supported sin=
ce 5.005<br>
=A0=A0=A0=A0=A0 (ABSTRACT_FROM=A0 =3D> 'lib/MyPackage.pm', # ret=
rieve abstract from module<br>=A0=A0=A0=A0=A0=A0 AUTHOR=A0=A0=A0=A0=A0=A0=
=A0=A0 =3D> 'James <james@>') : ()),<br>=A0=A0=A0 LIBS=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> [''], # e.g., '-lm=
'<br>
=A0=A0=A0 DEFINE=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> '', # e.g=
., '-DHAVE_SOMETHING'<br>=A0=A0=A0 INC=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0 =3D> '-I.', # e.g., '-I. -I/usr/include/othe=
r'<br>=A0=A0=A0 CC=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D>=
$CC,<br>=A0=A0=A0 LD=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> =
'$(CC)',<br>
=A0=A0=A0 XSOPT=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> '-C++',= <br>=A0=A0=A0 TYPEMAPS=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> ['perlobject.=
map' ],<br>=A0 # Un-comment this if you add C files to link with later:= <br>=A0=A0=A0 # OBJECT=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> '$(O_FI=
LES)', # link all the C files too<br>
);<br><br>and the typemap:<br><br>TYPEMAP<br>MyClass *=A0=A0=A0=A0=A0=A0=A0=
=A0 O_OBJECT<br><br><br>Cheers James<br>
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
Hi, I'm trying to write a XS routine to return a point to a c++ class to be
accessible from perl..
I'm new to XS, so i've been following:
http://www.johnkeiser.com/perl-xs-c++.html
and
http://search.cpan.org/~dmr/CookBookB-19960430/
However when I try make the xs generated code, i get the following compiler
error:
g++ -c -I. -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=3D64 -O2 -g -DVERSION=3D\"0.01\" -DXS_VERSION=3D\"0.0=
1\"
-fPIC "-I/usr/lib/perl/5.10/CORE" MyPackage.c
MyPackage.c: In function =91void XS_MyPackage_child(PerlInterpreter*, CV*)=
=92:
MyPackage.c:168: error: =91CLASS=92 was not declared in this scope
make: *** [MyPackage.o] Error 1
I assume I'm doing something wrong in the child method, however i lifted
this code out of one of the CookBookB examples..
MyClass *
MyClass::child()
CODE:
RETVAL =3D (MyClass *)safemalloc( sizeof(MyClass) );
*RETVAL =3D THIS->child();
OUTPUT:
RETVAL
CLEANUP:
safefree(RETVAL);
Any help would be much appreciated.
I have the following code:
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif
#undef list
#include <iostream>
class MyClass;
class MyClass {
private:
int _id;
public:
MyClass(int id) {
_id =3D id;
}
~MyClass() { }
void operator =3D(const MyClass &other) {
_id =3D other._id;
}
int id() {
return _id;
}
MyClass child() {
return MyClass(5);
}
};
MODULE =3D MyPackage PACKAGE =3D MyPackage
MyClass *
MyClass::new(int id)
void
MyClass::DESTROY()
MyClass *
MyClass::child()
CODE:
RETVAL =3D (MyClass *)safemalloc( sizeof(MyClass) );
*RETVAL =3D THIS->child();
OUTPUT:
RETVAL
CLEANUP:
safefree(RETVAL);
With the Makefile.PL:
use 5.010001;
use ExtUtils::MakeMaker;
$CC =3D 'g++';
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
NAME =3D> 'MyPackage',
VERSION_FROM =3D> 'lib/MyPackage.pm', # finds $VERSION
PREREQ_PM =3D> {}, # e.g., Module::Name =3D> 1.1
($] >=3D 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM =3D> 'lib/MyPackage.pm', # retrieve abstract from mod=
ule
AUTHOR =3D> 'James <james@>') : ()),
LIBS =3D> [''], # e.g., '-lm'
DEFINE =3D> '', # e.g., '-DHAVE_SOMETHING'
INC =3D> '-I.', # e.g., '-I. -I/usr/include/other'
CC =3D> $CC,
LD =3D> '$(CC)',
XSOPT =3D> '-C++',
TYPEMAPS =3D> ['perlobject.map' ],
# Un-comment this if you add C files to link with later:
# OBJECT =3D> '$(O_FILES)', # link all the C files too
);
and the typemap:
TYPEMAP
MyClass * O_OBJECT
Cheers James
--20cf3071cf6c40d4cb04a07667df
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
Hi, I'm trying to write a XS routine to return a point to a c++ class t=
o be accessible from perl..<br><br>I'm new to XS, so i've been foll=
owing:<br><br><a href=3D"http://www.johnkeiser.com/perl-xs-c++.html">http:/=
/www.johnkeiser.com/perl-xs-c++.html</a><br>
<br>and<br><br><a href=3D"http://search.cpan.org/~dmr/CookBookB-19960430/">=
http://search.cpan.org/~dmr/CookBookB-19960430/</a><br><br>However when I t=
ry make the xs generated code, i get the following compiler error:<br><br>
g++ -c=A0 -I. -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pip=
e -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET=
_BITS=3D64 -O2 -g=A0=A0 -DVERSION=3D\"0.01\" -DXS_VERSION=3D\&quo=
t;0.01\" -fPIC "-I/usr/lib/perl/5.10/CORE"=A0=A0 MyPackage.c=
<br>
MyPackage.c: In function =91void XS_MyPackage_child(PerlInterpreter*, CV*)=
=92:<br>MyPackage.c:168: error: =91CLASS=92 was not declared in this scope<=
br>make: *** [MyPackage.o] Error 1<br><br>I assume I'm doing something =
wrong in the child method, however i lifted this code out of one of the Coo=
kBookB examples..<br>
<br>MyClass *<br>
MyClass::child()<br>
=A0 CODE:<br>
=A0=A0=A0 RETVAL =3D (MyClass *)safemalloc( sizeof(MyClass) );<br>
=A0=A0=A0 *RETVAL =3D THIS->child();<br>
<br>
=A0 OUTPUT:<br>
=A0=A0=A0 RETVAL<br>
<br>
=A0 CLEANUP:<br>
=A0=A0=A0 safefree(RETVAL);<br><br>Any help would be much appreciated.<br><=
br>I have the following code:<br><br>#include "EXTERN.h"<br>#incl=
ude "perl.h"<br>#include "XSUB.h"<br><br>#include "=
;ppport.h"<br>
<br>#ifdef __cplusplus<br>=A0 extern "C" {<br>#endif<br>=A0=A0=A0=
#include "EXTERN.h"<br>=A0=A0=A0 #include "perl.h"<br>=
=A0=A0=A0 #include "XSUB.h"<br>#ifdef __cplusplus<br>=A0 }<br>#en=
dif<br><br>#undef list<br> <br>#include <iostream><br><br>class MyClass;<br><br>class MyClass {<=
br>=A0 private:<br>=A0=A0=A0 int _id;<br><br>=A0 public:<br>=A0=A0=A0 MyCla=
ss(int id) {<br>=A0=A0=A0=A0=A0 _id =3D id;<br>=A0=A0=A0 }<br>=A0=A0=A0 <br=
=A0=A0=A0 ~MyClass() { }<br><br>=A0=A0=A0 void operator =3D(const MyClass =
&other) {<br>=A0=A0=A0=A0=A0 _id =3D other._id;<br>=A0=A0=A0 }<br><br>=A0=A0=A0 int id()=
{<br>=A0=A0=A0=A0=A0 return _id;<br>=A0=A0=A0 }<br><br>=A0=A0=A0 MyClass c=
hild() {<br>=A0=A0=A0=A0=A0 return MyClass(5);<br>=A0=A0=A0 }<br>};<br><br>=
MODULE =3D MyPackage=A0=A0=A0 PACKAGE =3D MyPackage<br><br>MyClass *<br>
MyClass::new(int id)<br><br>void<br>MyClass::DESTROY()<br><br>MyClass *<br>=
MyClass::child()<br>=A0 CODE:<br>=A0=A0=A0 RETVAL =3D (MyClass *)safemalloc=
( sizeof(MyClass) );<br>=A0=A0=A0 *RETVAL =3D THIS->child();<br><br>=A0 =
OUTPUT:<br>=A0=A0=A0 RETVAL<br>
<br>=A0 CLEANUP:<br>=A0=A0=A0 safefree(RETVAL);<br><br>With the Makefile.PL=
:<br><br>use 5.010001;<br>use ExtUtils::MakeMaker;<br><br>$CC =3D 'g++&=
#39;;<br># See lib/ExtUtils/MakeMaker.pm for details of how to influence<br=
# the contents of the Makefile that is written.<br>
WriteMakefile(<br>=A0=A0=A0 NAME=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D=> 'MyPackage',<br>=A0=A0=A0 VERSION_FROM=A0=A0=A0=A0=A0 =3D> =
'lib/MyPackage.pm', # finds $VERSION<br>=A0=A0=A0 PREREQ_PM=A0=A0=
=A0=A0=A0=A0=A0=A0 =3D> {}, # e.g., Module::Name =3D> 1.1<br>=A0=A0=
=A0 ($] >=3D 5.005 ?=A0=A0=A0=A0 ## Add these new keywords supported sin=
ce 5.005<br>
=A0=A0=A0=A0=A0 (ABSTRACT_FROM=A0 =3D> 'lib/MyPackage.pm', # ret=
rieve abstract from module<br>=A0=A0=A0=A0=A0=A0 AUTHOR=A0=A0=A0=A0=A0=A0=
=A0=A0 =3D> 'James <james@>') : ()),<br>=A0=A0=A0 LIBS=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> [''], # e.g., '-lm=
'<br>
=A0=A0=A0 DEFINE=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> '', # e.g=
., '-DHAVE_SOMETHING'<br>=A0=A0=A0 INC=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0 =3D> '-I.', # e.g., '-I. -I/usr/include/othe=
r'<br>=A0=A0=A0 CC=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D>=
$CC,<br>=A0=A0=A0 LD=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> =
'$(CC)',<br>
=A0=A0=A0 XSOPT=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> '-C++',= <br>=A0=A0=A0 TYPEMAPS=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> ['perlobject.=
map' ],<br>=A0 # Un-comment this if you add C files to link with later:= <br>=A0=A0=A0 # OBJECT=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D> '$(O_FI=
LES)', # link all the C files too<br>
);<br><br>and the typemap:<br><br>TYPEMAP<br>MyClass *=A0=A0=A0=A0=A0=A0=A0=
=A0 O_OBJECT<br><br><br>Cheers James<br>