Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedding and calling Perl from C++

Status
Not open for further replies.

comma

Programmer
Feb 12, 2003
24
FI
Hi,

I'm trying to access Perl (subroutine) from C++ -program and seems that perlembed would be a good choise for that. I just would simply need to ivoke Perl, run script/call sub and then clean-up and continue in C++ program.

I've tried to run examples from e.g:
Code:
    #include <EXTERN.h>               /* from the Perl distribution     */
    #include <perl.h>                 /* from the Perl distribution     */

    static PerlInterpreter *my_perl;  /***    The Perl interpreter    ***/

    int main(int argc, char **argv, char **env)
    {
        my_perl = perl_alloc();
        perl_construct(my_perl);
	PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
        perl_parse(my_perl, NULL, argc, argv, (char **)NULL);
        perl_run(my_perl);
        perl_destruct(my_perl);
        perl_free(my_perl);
    }

but unfortunately with no luck (read many articles and done browsing, but didn't yet got it working). I'm running ActivePerl 5.8.7 on WindowsXP with MinGW/Msys and GCC 3.4.2. I constantly get the following kind of errors: "undefined reference to perl_alloc" (for all calls, with perl_*).

I have Perl installed to D:\Perl and the source test.cpp is located in the same directory. I used the following to compile:
gcc -DWIN32 -I/d/Perl/lib/CORE -L/d/Perl/lib/CORE -o test test.cpp

I was wondering if you would have good tips or tricks for embedding Perl into C++.

Thanks in advance!
 
The obvious suggestion it to write your perl as a stand alone script and execute it with backticks, system command or even a pipeline style "open".
Just a thought.


Trojan.
 
Sorry, it's late.
Other way around!
You have "system" and maybe "exec" in C/C++ I seem to remember.
I would be tempted to try calling the perl that way to start with.


Trojan.
 
Hi,

Thank you!
Yes, a "system" -call is possible to use and it works with that.

I was still wondering about exchanging information between C/C++ and Perl. Of course one possibility would be using SOAP, but that might add some overhead.

Is it possible to capture output from "system" command somehow? I could be then examined.

-comma
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top