How do I compile Perl code within a C program?
Asked Answered
T

3

7

I have a C program with an embedded Perl interpreter. I want to be able to precompile some Perl code from within the program. How do I do that?

Rationale (if anyone is interested) is to be able to compile it once, store the parse tree, and execute many times (as long as the compiled code does not change).

Thanks! Madhu

PS: I am using Perl-5.8, though it would be good to know if Perl-6.0 makes this easier in any way.

Thanatos answered 4/11, 2008 at 0:8 Comment(1)
wrt your rationale, are you embedding Perl just to store the parse tree and thus decrease startup time? Or does the C program do something else? If it's just for startup time, there's other ways to do that.Druid
F
12

This is the default behavior when you embed the Perl interpreter in a C program. After you've run perl_parse() to parse the Perl program, you can use perl_run() and call_argv() over and over with the same parsed Perl program.

Fawcette answered 4/11, 2008 at 0:15 Comment(0)
L
2

You can use perlcc to create executable or C sources.

To compile your C code, you would need to use perl's library (could be -lperl or -llibperl).

Laundromat answered 6/11, 2008 at 8:51 Comment(1)
If all you want is an executable binary, use PAR to do that. search.cpan.org/perldoc?ppDruid
D
0

In reference to Perl 6, it's not complete. But 5.10.0 might have some bug fixes over 5.8.

Druid answered 6/11, 2008 at 6:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.