Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Calling 'C' function from Perl

Reply
Thread Tools

Calling 'C' function from Perl

 
 
Sankar
Guest
Posts: n/a
 
      02-15-2007
Dear All,
I am developing a C application on a linux platform that has many
functions . My requirement is to call those functions from Perl.

I would appreciate if you could give some pointers in this regard.

My requirement is sth like this

C fucntion

int square( int a)
{
....
....
return(a)

}

in my perl file i should be able to do this.

a = square( 10)


Thanks in advance
Regards
Sankar

 
Reply With Quote
 
 
 
 
Marco Neumann
Guest
Posts: n/a
 
      02-15-2007
Hello, Sankar!

Try this module:

http://search.cpan.org/~ingy/Inline-0.44/C/C.pod
"
use Inline C;
greet('Ingy');
greet(42);
__END__
__C__
void greet(char* name) {
printf("Hello %s!\n", name);
}
"

Cheers,
Marco.


 
Reply With Quote
 
 
 
 
Mumia W.
Guest
Posts: n/a
 
      02-15-2007
On 02/14/2007 11:49 PM, Sankar wrote:
> Dear All,
> I am developing a C application on a linux platform that has many
> functions . My requirement is to call those functions from Perl.
>
> I would appreciate if you could give some pointers in this regard.
> [...]


perldoc perlxs


--
Windows Vista and your freedom in conflict:
http://techdirt.com/articles/20061019/102225.shtml
 
Reply With Quote
 
Sisyphus
Guest
Posts: n/a
 
      02-15-2007

"Sankar" <> wrote in message
news: ups.com...
> Dear All,
> I am developing a C application on a linux platform that has many
> functions . My requirement is to call those functions from Perl.
>
> I would appreciate if you could give some pointers in this regard.
>
> My requirement is sth like this
>
> C fucntion
>
> int square( int a)
> {
> ...
> ...
> return(a)
>
> }
>


Marco has pointed you in the right direction. More specifically:

-----------------
use warnings;
use Inline C => Config =>
BUILD_NOISY => 1;

use Inline C => <<'EOC';

int square(int a) {
return a * a;
}

EOC

$a = 173;
$a = square($a);
print $a, "\n";
-----------------

Cheers,
Rob


 
Reply With Quote
 
Sankar
Guest
Posts: n/a
 
      02-15-2007
On Feb 15, 5:30 am, "Sisyphus" <sisyph...@nomail.afraid.com> wrote:
> "Sankar" <writetoshan...@gmail.com> wrote in message
>
> news: ups.com...
>
>
>
> > Dear All,
> > I am developing a C application on a linux platform that has many
> > functions . My requirement is to call those functions from Perl.

>
> > I would appreciate if you could give some pointers in this regard.

>
> > My requirement is sth like this

>
> > C fucntion

>
> > int square( int a)
> > {
> > ...
> > ...
> > return(a)

>
> > }

>
> Marco has pointed you in the right direction. More specifically:
>
> -----------------
> use warnings;
> use Inline C => Config =>
> BUILD_NOISY => 1;
>
> use Inline C => <<'EOC';
>
> int square(int a) {
> return a * a;
>
> }
>
> EOC
>
> $a = 173;
> $a = square($a);
> print $a, "\n";
> -----------------
>
> Cheers,
> Rob


Thanks a lot everyone for your response.. Ur help is greatly
appreciated !!

Regards
Sankar

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Flash calling Php calling Perl Bill H Perl Misc 3 06-04-2009 03:32 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
calling virtual function results in calling function of base class... Andreas Lagemann C++ 8 01-10-2005 11:03 PM
calling virtual function results in calling function of base class ... tiwy C++ 0 01-09-2005 11:17 PM
problem calling perl script from SOAP server perl script pj Perl Misc 3 04-09-2004 10:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57