in reply to Re^4: Attempt to embed Perl in C on Windows
in thread Attempt to embed Perl in C on Windows

The perl source file can be included if provided with full path with double backslash.

Sorry it was a rapid shot, since I still need the perl source file at the runtime. The desired behavior were to pack the source file at the compile time. Is it possible?

  • Comment on Re^5: Attempt to embed Perl in C on Windows

Replies are listed 'Best First'.
Re^6: Attempt to embed Perl in C on Windows
by BrowserUk (Patriarch) on Dec 23, 2014 at 18:25 UTC
    The desired behavior were to pack the source file at the compile time. Is it possible?

    What do you mean by "How to bind the perl source file" and/or "pack the source file"?

    Do you mean:

    1. Embed the path/name of the source file in the executable?
    2. Embed the contents of the source file in the executable?
    3. Other?

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      I meant "Embed the contents of the source file in the executable". Sorry for the ambiguity and thank you very much for your time.

        [Can I ]"Embed the contents of the source file in the executable".

        Yes, though doing so is a bit of a faff and you need to copy&paste and build a multiline string in C.

        The MULTLINE() macro below does that, but you need to add \n at the end any line where that is important (eg. the shebang line). For most other lines you don't need to bother, as Perl happily compiles whole programs as one line:

        #include <EXTERN.h> #include <perl.h> EXTERN_C void xs_init (pTHX); EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); EXTERN_C void boot_Win32CORE (pTHX_ CV* cv); EXTERN_C void xs_init(pTHX) { char *file = __FILE__; dXSUB_SYS; /* DynaLoader is a special case */ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); newXS("Win32CORE::bootstrap", boot_Win32CORE, file); } static PerlInterpreter *my_perl; /*** The Perl interpreter ***/ #define MULTILINE(...) #__VA_ARGS__ static char code[] = MULTILINE( #! perl -slw\n use strict; print "Hello from $^O $]\n"; ); int main(int argc, char **argv, char **env) { char *embedding[] = { "", "-e", "0" }; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_parse(my_perl, NULL, 3, embedding, NULL); perl_run(my_perl); // Execute embedded program eval_pv(code, TRUE); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); return 0; }

        C:\test>cl /W3 -DWIN32 hello.c -I"C:\Perl64\lib\CORE" C:\Perl64\lib\C +ORE\perl510.lib Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64 Copyright (C) Microsoft Corporation. All rights reserved. hello.c Microsoft (R) Incremental Linker Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. /out:hello.exe hello.obj C:\Perl64\lib\CORE\perl510.lib C:\test>.\hello.exe Hello from MSWin32 5.010001

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.