CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Need help in doing C / Perl interface

 



abhinav_shaan
New User

Feb 7, 2007, 1:44 AM

Post #1 of 6 (919 views)
Need help in doing C / Perl interface Can't Post

I need something like this

For example , a c program is running and creates a global database.
Also there are functions which return the global data.

At the end of the C++ program i want to call/source a perl file from within the program. THis perl file will
call the above mentioned functions and print the values,
assuming everything is numerical.

Please tell me if this is doable. if yes , please let me know.

Thanx
Abhinav


ProBulletin
Novice

Feb 7, 2007, 8:51 AM

Post #2 of 6 (918 views)
Re: [abhinav_shaan] Need help in doing C / Perl interface [In reply to] Can't Post

This isn't really a beginner topic, but you probably need to look at XSUBs.

http://www.perl.com/doc/manual/html/pod/perlxs.html


Regards,
Paul Wilson
ProBulletin Board: http://www.probulletin.com/


davorg
Thaumaturge / Moderator

Feb 9, 2007, 8:24 AM

Post #3 of 6 (905 views)
Re: [abhinav_shaan] Need help in doing C / Perl interface [In reply to] Can't Post

Is this a self-contained Perl program that you want to call? In that case you just want to use "system" or whatever method C uses for calling external programs.

If you want the Perl code embedded within your C program, then you'll need to look at "perldoc perlembed" - but that can get a bit hairy.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


davorg
Thaumaturge / Moderator

Feb 9, 2007, 8:29 AM

Post #4 of 6 (904 views)
Re: [ProBulletin] Need help in doing C / Perl interface [In reply to] Can't Post


In Reply To
This isn't really a beginner topic, but you probably need to look at XSUBs.


That's for calling C from Perl. I think he wants to do the opposite.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


ProBulletin
Novice

Feb 9, 2007, 8:50 AM

Post #5 of 6 (903 views)
Re: [davorg] Need help in doing C / Perl interface [In reply to] Can't Post


Quote
That's for calling C from Perl.


You can do the opposite too.


Regards,
Paul Wilson
ProBulletin Board: http://www.probulletin.com/


(This post was edited by ProBulletin on Feb 9, 2007, 8:50 AM)


abhinav_shaan
New User

Feb 11, 2007, 10:13 PM

Post #6 of 6 (890 views)
Re: [ProBulletin] Need help in doing C / Perl interface [In reply to] Can't Post

Hi,

thanx for the responses.
i will make my requirement more clear using an example.

Imagine my C/C++ file looks like this :

//*************** FILE BEGINS**************
int a;

void setI()
{
a = 10;
}

int returnI()
{
return a;
}

void main()
{
setI();
// : Pseudo call to a perl file. This is what i need to know
system("source test.pl");
}

// : C file ends

NOw, i dont know perl syntax much , but this i how i imagine test.pl woulod look like

**************** test.pl file ****************

use ....
....
....
my $x
$x = getI() // : This is the call to the C function.
print($x);
.....
.....

****************** end ***************************

I want to build the C code as an executable so that on running the main
function , that value 'a' should be set , then the perl file should be
sourced which calls the getI() function and prints the returned value.


I have tried using the Inline option provided in Perl. It works
for small programs like above , but it requires that i right the C code in the perl file itself. I want a way to avoid writing the C code in the perl file
i just want some way that an interface to an existing code / data structure can be created.

Thanks,
Abhinav

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives