Everything works, except that I really need this to be statically linked so that I only have a single executable that packs the Perl libraries + the LibYAML XS libs. I need it that way for distribution purposes where no Perl or LibYAML can be installed (but other dependencies may be ok, like LibC, etc.).
Like a Golang freak colleague says, this would be "just like Go". He urges me to use Go instead, but I just can't believe a C-Perl compiled interpreter could not do the job just as well :)
Searching around in the we takes me to staticperl, which is a quite complicated beast, based on Perl 5.12 and not really what I'm looking for.
Here's a proof-of-concept program and the compilation line.
#include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { PERL_SYS_INIT3(&argc,&argv,&env); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; char *embedding[] = { "", "-e", "0" }; my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 3, embedding, NULL); perl_run(my_perl); eval_pv( "use YAML::XS;", TRUE ); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
cc myprog.c -o myprog `perl -MExtUtils::Embed -e ccopts -e ldopts`
Note I'm not using the Dynaloader in this example as I assume, if correctly linked as a static binary, my binary would not need Perl's Dynaloader... right?
In reply to Compiling C program with a Static Perl by rodd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |