Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

How to call C++ from perl

by pcouderc (Monk)
on Apr 19, 2004 at 18:39 UTC ( #346395=perlquestion: print w/replies, xml ) Need Help??

pcouderc has asked for the wisdom of the Perl Monks concerning the following question:

I have some C++ suroutine soon written, that I want to call from perl. Where is there a HowTo do that?
Thank you
Pierre Couderc

Replies are listed 'Best First'.
Re: How to call C++ from perl
by dug (Chaplain) on Apr 19, 2004 at 18:46 UTC
Re: How to call C++ from perl
by saintmike (Vicar) on Apr 19, 2004 at 18:55 UTC
Re: How to call C++ from perl
by halley (Prior) on Apr 19, 2004 at 18:51 UTC
    Your best bet would be to make a C routine (with extern "C" declaration) which can call your C++ routine properly. Calling C++ directly is a bit of an issue thanks to a problem called "decoration" which is difficult to manage from any other language. Then your Perl can call the simple C functions in a fairly straightforward way.

    To see more about how to call C from Perl, see perlxs and perlguts. The inverse, how to call Perl from C, you can find in perlembed.

    Update: Inline::CPP is another option, but requires you to compile the code when you run the script. This may or may not be convenient for your scripting and distribution purposes.

    [ e d @ h a l l e y . c c ]

Re: How to call C++ from perl
by pcouderc (Monk) on Apr 20, 2004 at 07:37 UTC
    Thank you to all of you. I have so many ways now...!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://346395]
Approved by broquaint
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2023-06-10 01:36 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (36 votes). Check out past polls.