Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Call C functions from Perl

by gzayzay (Sexton)
on Apr 23, 2008 at 21:15 UTC ( #682498=perlquestion: print w/ replies, xml ) Need Help??
gzayzay has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

I am trying to venture in something quit new to me and will like to know if it is possible to call a c-function from a Perl script.

Say I have a VS C project I have created. Included in the VS project I have a function call createSocket(). This c-function when called, triggers a TCP/IP connection with my Perl module say ModuleA. In ModuleA, (that is Perl) can I call a doSomething() c-function that resides in my VS project that will inturn call createSocket().

If it is possible, can any monk kindly demonstrate how I can go about doing that?

Comment on Call C functions from Perl
Re: Call C functions from Perl
by Joost (Canon) on Apr 23, 2008 at 21:31 UTC
    if it is possible to call a c-function from a Perl script.
    Yes it is.
    Say I have a VS C project I have created. Included in the VS project I have a function call createSocket(). This c-function when called, triggers a TCP/IP connection with my Perl module say ModuleA. In ModuleA, (that is Perl) can I call a doSomething() c-function that resides in my VS project that will inturn call createSocket().
    You seem to be talking about both calling perl functions/methods from C and the reverse. Both are possible, and pretty well supported and documented, but it's a fairly advanced topic. You should read perlxstut, perlxs, perlembed and perlapi. Those are good resources and free (and probably the definitive word on the topic aside from reading the source to perl itself), but I recommend you get the extending and embedding perl book as an introduction to the topic. You'll still need the man pages, but the book will give you a good overview of what's possible, how to tackle the problems in general and just generally show you by example.

Re: Call C functions from Perl
by mscharrer (Hermit) on Apr 23, 2008 at 21:33 UTC
    You can call C functions from Perl. The simplest way AFIK is using Inline::C. I don't have any experience using it together with a VS C compiler, I just used it a few times with the GCC under Linux.

    Another way to call C code from Perl is using XS, but IMHO it's only for advanced Perl programmers, e.g. to write Perl extensions.

      Or better, take the xs code that Inline::C generated and use it directly.


      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Re: Call C functions from Perl
by wade (Pilgrim) on Apr 23, 2008 at 22:18 UTC
Re: Call C functions from Perl
by BrowserUk (Pope) on Apr 23, 2008 at 22:20 UTC
Re: Call C functions from Perl
by tachyon-II (Chaplain) on Apr 24, 2008 at 00:56 UTC
Re: Call C functions from Perl
by jeepj (Scribe) on Apr 24, 2008 at 12:54 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2014-12-28 18:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls