Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

calling perl program from C++

by baperl (Sexton)
on Oct 01, 2011 at 21:00 UTC ( #929064=perlquestion: print w/ replies, xml ) Need Help??
baperl has asked for the wisdom of the Perl Monks concerning the following question:

hi, I am trying to compile this program
#include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *args[] = { NULL }; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, argc, argv, NULL); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; /*** skipping perl_run() ***/ call_argv("showtime", G_DISCARD | G_NOARGS, args); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
but I get the following error
g++ fn-test.cpp -o t 'perl -MExtUtils::Embed -e ccopts -e ldopts' g++: perl -MExtUtils::Embed -e ccopts -e ldopts: No such file or direc +tory fn-test.cpp:2:24: fatal error: EXTERN.h: No such file or directory compilation terminated.
I am working on ubuntu so I went into cpan and ran
force install ExtUtils::Embed
it did it's thing for a while and now when I try to compile again, I get the same error. This is my first time trying to call a Perl program from C++, so any tips would be helpful.

Comment on calling perl program from C++
Select or Download Code
Re: calling perl program from C++
by ikegami (Pope) on Oct 01, 2011 at 21:28 UTC

    You're using the wrong quotes. You are passing

    perl -MExtUtils::Embed -e ccopts -e ldopts

    as an argument instead of embedding its output in the shell command. Use backticks.

      well that works, but now my other perl programs give me the following error
      Can't locate Date/Manip.pm in @INC (@INC contains: /usr/local/lib/per +l5/site_perl/5.15.2/i686-linux /usr/local/lib/perl5/site_perl/5.15.2 +/usr/local/lib/perl5/5.15.2/i686-linux /usr/local/lib/perl5/5.15.2 .) +
      I went into CPAN and ran force install Date::Manip but it doesn't seem to work...any suggestions....I had it working before I ran the force install ExtUtils::Embed

        ExtUtils::Embed is part of the perl distro. You told cpan to force the installation of Perl. God knows what effect that had, but I'm not going to try it to find out.

Re: calling perl program from C++
by Anonymous Monk on Oct 02, 2011 at 12:28 UTC
    I don't want to say "RTFM" because that's not nice, but ... "go back and study the published examples very, very carefully."
Reaped: Re: calling perl program from C++
by NodeReaper (Curate) on Oct 03, 2011 at 13:22 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-12-29 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (187 votes), past polls