Ok, this is a cross-posting from StackOverflow http://stackoverflow.com/questions/27058788/attempt-to-embed-perl-in-c-on-windows . I posted it there first because I thought it is more C than Perl question. However I did not get any answer and so I'd like to try it again.

I am trying to run the following example from http://perl-node-interface.blogspot.de/2011/03/deploy-perl-application-on-windows.html (is not accepted as link) with a simple "Hello.pl" (just prints "Hello" to STDOUT).

It fails. The .exe file is created but does not produce any output.

Probably this is my basic misunderstanding. Could you please point me in the right direction? Btw. the "lib folder containing all dependencies" in the project folder is empty since there are no modules in the "hello.pl". Is this a correct assumption?

Thank you very much!

The hello.c file:

#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 ***/ int main(int argc, char **argv, char **env) { argv[1] = "-Ilib"; argv[2] = "hello.pl"; 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, argc, argv, (char **)NULL); perl_run(my_perl); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }

The perl file to build the compiler command:

#!/perl use strict; use warnings FATAL => qw(all); use ExtUtils::Embed; print "\nBuilding Hello\n"; my $gcc_cmd = join( ' ' , 'C:\Perl_516_portable\c\bin\gcc -Wall -mwind +ows -o K:\Scripts\Embed\Hello_3\hello K:\Scripts\Embed\Hello_3\hello. +c', &ccopts, &ldopts ); print STDOUT $gcc_cmd , "\n"; system( $gcc_cmd );

The output:

---------------------------------------------- Perl executable: C:\Perl_516_portable\perl\bin\perl.exe Perl version : 5.16.3 / MSWin32-x86-multi-thread C:\Perl_516_portable>perl K:\Scripts\Embed\Hello_3\building_3.pl Building Hello C:\Perl_516_portable\c\bin\gcc -Wall -mwindows -o K:\Scripts\Embed\He +llo_3\hello K:\Scripts\Embed\Hello_3\hello.c -s -O2 -DWIN32 -DPERL +_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-st +rict-aliasing -mms-bitfields -I"C:\Perl_516_portable\perl\lib\CORE" + -s -L"C:\Perl_516_portable\perl\lib\CORE" -L"C:\Perl_516_portable\ +c\lib" C:\Perl_516_portable\perl\lib\CORE\libperl516.a C:\Perl_516_p +ortable\c\i686-w64-mingw32\lib\libmoldname.a C:Perl_516_portable\c\i6 +86-w64-mingw32\lib\libkernel32.a C:\Perl_516_portable\c\i686-w64-ming +w32\lib\libuser32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libgd +i32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libwinspool.a C:\Pe +rl_516_portable\c\i686-w64-mingw32\lib\libcomdlg32.a C:\Perl_516_port +able\c\i686-w64-mingw32\lib\libadvapi32.a C:\Perl_516_portable\c\i686 +-w64-mingw32\lib\libshell32.a C:\Perl_516_portable\c\i686-w64-mingw32 +\lib\libole32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\liboleaut +32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libnetapi32.a C:\Per +l_516_portable\c\i686-w64-mingw32\lib\libuuid.a C:\Perl_516_portable\ +c\i686-w64-mingw32\lib\libws2_32.a C:Perl_516_portable\c\i686-w64-min +gw32\lib\libmpr.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libwinm +m.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libversion.a C:\Perl_ +516_portable\c\i686-w64-mingw32\lib\libodbc32.a C:\Perl_516_portable\ +c\i686-w64-mingw32\lib\libodbccp32.a C:\Perl_516_portable\c\i686-w64- +mingw32\lib\libcomctl32.a In file included from C:\Perl_516_portable\perl\lib\CORE/sys/socket.h: +180:0, from C:\Perl_516_portable\perl\lib\CORE/win32.h:356, from C:\Perl_516_portable\perl\lib\CORE/win32thread.h:4, from C:\Perl_516_portable\perl\lib\CORE/perl.h:2834, from K:\Scripts\Embed\Hello_3\hello.c:2: C:\Perl_516_portable\perl\lib\CORE/win32.h:361:26: warning: "/*" withi +n comment [-Wcomment] C:\Perl_516_portable\perl\lib\CORE/win32.h:362:33: warning: "/*" withi +n comment [-Wcomment] In file included from C:\Perl_516_portable\perl\lib\CORE/win32thread.h +:4:0, from C:\Perl_516_portable\perl\lib\CORE/perl.h:2834, from K:\Scripts\Embed\Hello_3\hello.c:2: C:\Perl_516_portable\perl\lib\CORE/win32.h:361:26: warning: "/*" withi +n comment [-Wcomment] C:\Perl_516_portable\perl\lib\CORE/win32.h:362:33: warning: "/*" withi +n comment [-Wcomment] K:\Scripts\Embed\Hello_3\hello.c: In function 'main': K:\Scripts\Embed\Hello_3\hello.c:37:1: warning: control reaches end of + non-void function [-Wreturn-type]

In reply to Attempt to embed Perl in C on Windows by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.