Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

can we call c++ in perl to process PDL arrays?

by toothedsword (Sexton)
on Nov 09, 2019 at 02:27 UTC ( [id://11108506]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Dear,

I want to call c++ functions in perl(using .o files), I know how to call fortran or c from PDL, so can we call c++?

I have tried but failed.

Leon

Replies are listed 'Best First'.
Re: can we call c++ in perl to process PDL arrays?
by GrandFather (Saint) on Nov 09, 2019 at 06:16 UTC

    It works just the same a C except that C++ mangles function names so you must mark the functions you wish to call as extern "C". The functions can not be non-static member functions.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
      Thank you so much, I will try it.
Re: can we call c++ in perl to process PDL arrays?
by karlgoethebier (Abbot) on Nov 09, 2019 at 09:36 UTC

    Probably this is good for you? Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

      Thank you, but this method can be used for PDL array?
        You'd need to use Inline with => 'PDL' to make available PDL's C functions. Then, to know what PDL C functions to actually call, consult PDL::API.

        The imminent PDL::OpenCV (not on CPAN yet, but see https://github.com/PDLPorters/pdl/issues/362) shows how to call from PDL C code into C++ via a wrapper, if that's any use.

        EDIT: "how to" is too strong - "one way to" would be better.

        Hi toothedsword, I don‘t really know it and i’m not sure. I guessed. And i fear that you must try/figure it out yourself. Yet another experiment 😎 Best regards, Karl

        «The Crux of the Biscuit is the Apostrophe»

        perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re: can we call c++ in perl to process PDL arrays?
by learnedbyerror (Monk) on Nov 11, 2019 at 00:53 UTC

    You may want to consider FFI::Platypus as opposed to more manual methods.

    Good Luck, lbe

      Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-03-28 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found