spacepaste

  1.  
  2. $ cat ./perlportable.c
  3. #include <EXTERN.h>
  4. #include <perl.h>
  5. /* we're going to embed two interpreters */
  6. #define SAY_HELLO "-e", "$string = $^X; $string =~ s/.*\///; $newstring = $^X ; $newstring =~ s/$string//; print $newstring;"
  7. int main(int argc, char **argv, char **env)
  8. {
  9. PerlInterpreter *one_perl;
  10. char *one_args[] = { "one_perl", SAY_HELLO };
  11. PERL_SYS_INIT3(&argc,&argv,&env);
  12. one_perl = perl_alloc();
  13. PERL_SET_CONTEXT(one_perl);
  14. perl_construct(one_perl);
  15. perl_parse(one_perl, NULL, 3, one_args, (char **)NULL);
  16. perl_run(one_perl);
  17. perl_destruct(one_perl);
  18. perl_free(one_perl);
  19. PERL_SYS_TERM();
  20. }
  21. $ gcc libperl.a perlportable.c -Wl,-E -fstack-protector-strong -L/usr/local/lib -L/home/zorin-os/UPM/perl5.26/lib/5.26.0/x86_64-linux/CORE -lperl -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
  22. -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/home/zorin-os/UPM/perl5.26/lib/5.26.0/x86_64-linux/CORE
  23. perlportable.c:1:20: fatal error: EXTERN.h: No such file or directory
  24. compilation terminated.
  25. bash: line 1: -fwrapv: command not found
  26. $ ./a.out
  27. syntax error at -e line 1, near "/;"
  28. Execution of -e aborted due to compilation errors.
  29.