Intro
I'm trying to create a PerlXS-Modul, that uses a C++ Class. Before diving into the complex matter, I wanted to create a little Test, to see how the basics work, since this is my first time using PerlXS. Luckily I tumbled upon this http://www.perlmonks.org/?node_id=853194 thread, which is a pretty awesome piece of knowledge. So I started to create my own litte Testclass, according to the example in the tutorial.The Problem
While 'make' works without errors, but the include ( make test etc.) of the modul into a perl script fails with the following error:I tried to as close a possibly with the tutorial, but something is off, and I don't know what. Has anyone seen something similar? Any hints?Error: Can't load '/home/dr/Abby/XS/Mytest/blib/arch/auto/Mytest/Myte +st.so' for module Mytest: /home/dr/Abby/XS/Mytest/blib/arch/auto/Myte +st/Mytest.so: undefined symbol: _ZN7MyClassD1Ev at /usr/lib/perl/5.14 +/DynaLoader.pm line 184.
Code
I created the folder structure using h2xs -A -n Mytest In there I created a folder, called 'myclass', where the code for my C++ ClassC++ Part
myclass.hmyclass.cpp#ifndef MyClass_H #define MyClass_H class MyClass { public: MyClass(int a, int b); ~MyClass(); int area(); private: int length; int width; }; #endif
To test all these I wrote a litte unitTest, which worked fine. So I can safely assume, that my problem is not within the C++ part.#include "myclass.h" using namespace std; MyClass::MyClass (int length, int width) { this->length = length; this->width = width; } int MyClass::area() { return this->length*this->width; } </class> Makefile.PL This I basically took from the Tutorial mentioned in the Into, and adj +usted it to my changes. <code> use ExtUtils::MakeMaker; my ( $CC, $Verbose ) = ( 'g++', 1 ); WriteMakefile( NAME => 'Mytest::myclass', SKIP => [qw(all static static_lib dynamic dynamic_lib)], clean => {'FILES' => 'libmyclass$(LIB_EXT) unitTest'}, CC => $CC, # Our CPP compiler LD => '$(CC)', CCFLAGS => '-fPIC', # this instructs the CPP compiler to use "Posi +tion independence", basically a shared library, more details here # http://www.fpx.de/fp/Software/tcl-c++/tc ++l-c++.html ); sub MY::top_targets { ' all :: static pure_all :: static static :: libmyclass$(LIB_EXT) libmyclass$(LIB_EXT): $(O_FILES) $(AR) cr libmyclass$(LIB_EXT) $(O_FILES) $(RANLIB) libmyclass$(LIB_EXT) bin: $(O_FILES) $(LD) $(O_FILES) -o unitTest '; }
XS-Part and Makefile.PL
Mytest.xstypemap MyClass * T_PTROBJ Makefile.PL#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include "myclass/myclass.h" MODULE = Mytest PACKAGE = Mytest MyClass* MyClass::new(int a, int b) int MyClass::area() void MyClass::DESTROY()
t/Mytest.tuse 5.014002; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. my $CC = 'g++'; WriteMakefile( NAME => 'Mytest', VERSION_FROM => 'lib/Mytest.pm', # finds $VERSION PREREQ_PM => {}, # e.g., Module::Name => 1.1 CC => $CC, # Our CPP compiler LD => '$(CC)', ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/Mytest.pm', # retrieve abstract from mod +ule AUTHOR => 'Dennis Rieber <dr@>') : ()), LIBS => [''], # e.g., '-lm' DEFINE => '', # e.g., '-DHAVE_SOMETHING' INC => '-I.', # e.g., '-I. -I/usr/include/other' # Un-comment this if you add C files to link with later: # OBJECT => '$(O_FILES)', # link all the C files too MYEXTLIB => 'myclass/libmyclass$(LIB_EXT)', # TYPEMAPS => ['perlobject.map' ], ); sub MY::postamble { ' $(MYEXTLIB): myclass/Makefile cd myclass && $(MAKE) $(PASSTHRU) '; }
MANIFEST# Before `make install' is performed this script should be runnable wi +th # `make test'. After `make install' it should work as `perl Mytest.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use strict; use warnings; use Test::More tests => 2; BEGIN { use_ok('Mytest') }; my $class = new Mytest::MyClass(2,3); is($class->area(), 6, 'area_ok') ######################### # Insert your test code below, the Test::More module is use()ed here s +o read # its man page ( perldoc Test::More ) for help writing this test scrip +t.
This should be all the relevant code, or did I miss something?Changes Makefile.PL MANIFEST Mytest2.xs ppport.h README t/Mytest2.t lib/Mytest2.pm
In reply to Unable to use created PerlXS Modul ( using c++ ) by lamchob
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |