Calling C++ from Perl and vice versa

D

Divick

I am a PERL newbie. Does any one know how can I call Perl functions
from my C++ program and vice versa? Also I want it to be portable i.e.
I can use whatever module /package both on linux and windows. I use to
program with TCL and I have done interfacing of a C program with TCL,
thus I assume that doing so would be much easier and supported on Perl
(IMO especially when Perl is a better language than TCL as far as
scripting goes).

I checked this newsgroup for similar keywords but it seems like people
are suggesting to use system call even when they know with this one can
only call Perl from C++ but cannot getback the result of some function
in Perl.

Thanks,
Divick
 
P

Paul Lalli

Divick said:
I am a PERL newbie. Does any one know how can I call Perl functions
from my C++ program and vice versa?
I checked this newsgroup for similar keywords

But you didn't check the Perl FAQ, did you?

perldoc -q "C with Perl"
which leads you to a FAQ found in perlfaq3, which leads you to *many*
documents describing how to interconnect the two languages

Paul Lalli
 
D

Divick

hmm.. got it thanks for it. Managed to call a perl function from "C".
Still need to figure out how to pass and return values from perl.

Anyways thanks for the reply,
Divick
 
S

Sisyphus

Divick said:
hmm.. got it thanks for it. Managed to call a perl function from "C".
Still need to figure out how to pass and return values from perl.

Inline-0.44 from CPAN (which includes Inline::C) would be my recommendation.
(There's also Inline::CPP.)
Or you may like to get straight into compiling XS code (which is more or
less what Inline::C automates for you) - in which case you'd probably start
with 'perldoc perlxstut'.

Cheers,
Rob
 
M

Markus Dehmann

Sisyphus said:
Inline-0.44 from CPAN (which includes Inline::C) would be my recommendation.
(There's also Inline::CPP.)
Or you may like to get straight into compiling XS code (which is more or
less what Inline::C automates for you) - in which case you'd probably start
with 'perldoc perlxstut'.

You can also look at http://www.swig.org

It is "a relatively quick and painless way of exposing your C/C++
program's internal API to the machinations of any scripting language."
(http://codeguru.com/csharp/.net/net_asp/scripting/article.php/c11103)

Markus
 
D

Divick

Inline-0.44 from CPAN (which includes Inline::C) would be my recommendation.
What is that supposed to mean? Are all the above achieve the same
purpose? If not then which is for what purpose? I assume that my
question is pretty straight forward and also that there must be some
easier way of achieving the target/question that I have. That is out of
the above what shall I pick to implement what I want? What is the
deciding factor?

Thanks,
Divick
 
S

Sisyphus

Divick said:
What is that supposed to mean? Are all the above achieve the same
purpose?

Yes - in that they're all about calling C from Perl. (I think you've already
been able to call Perl from C.)
If not then which is for what purpose? I assume that my
question is pretty straight forward and also that there must be some
easier way of achieving the target/question that I have.

Your question *is* straightforward. Unfortunately that doesn't guarantee
that the answer is straightforward - and I know of no "easier way of
achieving the target/question" than using the Inline module.
That is out of
the above what shall I pick to implement what I want? What is the
deciding factor?

I think it's best that you just take a look at the Inline::C documentation
(including the Inline::C-Cookbook), the Inline::CPP documentation, 'perldoc
perlxstut' documentation - and decide for yourself what your own preference
is.

Cheers,
Rob
 
D

Divick

Ok sounds fine. Will have a look at them and then decide myself what to
choose in that case since there is no clear cut answer.

Thanks,
Divick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top