Hallo list members,
Has anybody succeded in using already existing c++ libraries form within
the perl code?
I tried with Inline::CPP (see below)
Only the classes or methods I provide definitions for are accessable from
within perl.
Do I really have to wrap up all the functions in the library?
And how can I get rid of the warning about not finding main::Person?
(My knowledge of c++ is quite limited )
Carola Begemann
The following skript does work with perl 5.6.1 ; Inline 0.43 ,Inline::CPP
0.23
(Operaing System is SuSE Linux 7.2 kernel 2.2.19)
----------------------------------------------------------
#!/usr/bin/perl -w
use Inline (Config =>
PRINT_INFO => 1
);
use Inline 'CPP';
use Inline 'CPP' => Config => LIBS => '-L/home/cbe/Perltest/SOURCE/
-lPerson';
use strict;
my $obj = new Junge ("Dieter" , 8);
$obj->pprint_name();
my $age = $obj->phow_old();
my $name = $obj->pget_name();
print "$name is $age years old\n";
__END__
__CPP__
#include "/home/cbe/Perltest/SOURCE/Person.h"
class Junge : public Person {
public:
Junge (char *name, int age) ;
~Junge();
int phow_old () ;
int phappy_birthday();
void pprint_name();
char* pget_name();
/* and inherits all the methods I map tose on */
private :
char *name;
int age;
};
/* Functions for Junge */
Junge::Junge (char *name, int age) : Person::Person (name,age) {;
}
Junge::~Junge () {
;}
int Junge::phow_old () {
int a;
a = this->how_old();
return a;
}
int Junge::phappy_birthday () {
int a;
a = this->happy_birthday();
return a;
}
void Junge::pprint_name () {
this->print_name();
}
char* Junge::pget_name () {
char *n;
n = this->get_name();
return n;
}
---------------------------------------------------------------------------
Generated output
<-----------------------Information
Section----------------------------------->
Information about the processing of your Inline CPP code:
Your module is already compiled. It is located at:
/home/cbe/Perltest/INLINE/lib/auto/Itest/Itest.so
Use of uninitialized value in string comparison (cmp) at
/usr/lib/perl5/site_perl/5.6.1/Inline/CPP.pm line 125.
Use of uninitialized value in string comparison (cmp) at
/usr/lib/perl5/site_perl/5.6.1/Inline/CPP.pm line 125.
Use of uninitialized value in string comparison (cmp) at
/usr/lib/perl5/site_perl/5.6.1/Inline/CPP.pm line 125.
The following C++ classes have been bound to Perl:
class Junge : public Person {
Junge::Junge(char * name, int age);
char * Junge::pget_name();
int Junge::phappy_birthday();
int Junge::phow_old();
void Junge::pprint_name();
Junge::~Junge();
};
No C++ functions have been bound to Perl.
<-----------------------End of Information
Section---------------------------->
Can't locate package main::Person for @main::Junge::ISA at inline_4.pl
line 17.
This person's name is Dieter
Dieter is 8 years old
------------------------------------------------------------------------------------------------------------------------