rodd has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Compiling C program with a Static Perl
by Corion (Patriarch) on Sep 03, 2017 at 10:12 UTC | |
|
Re: Compiling C program with a Static Perl
by zakame (Pilgrim) on Sep 03, 2017 at 15:11 UTC | |
|
Re: Compiling C program with a Static Perl
by RonW (Parson) on Sep 06, 2017 at 23:13 UTC | |
by afoken (Chancellor) on Sep 07, 2017 at 06:40 UTC | |
|
Re: Compiling C program with a Static Perl
by Anonymous Monk on Sep 03, 2017 at 11:55 UTC | |
by Your Mother (Archbishop) on Sep 03, 2017 at 15:10 UTC | |
by rodd (Scribe) on Sep 03, 2017 at 19:31 UTC | |
by Anonymous Monk on Sep 03, 2017 at 21:17 UTC | |
by rodd (Scribe) on Sep 04, 2017 at 00:27 UTC | |
|