Personally I use the ExtUtils::Embed option to generate the xs_init() code, and link that into my binary that includes perl functionality.

Parts of my Makefile look like this:

CONFIG_PM=-MConfig PRIVLIB=`$(PERL) $(CONFIG_PM) -e 'print $$Config{privlibexp}'` EXTUTILS_EMBED = $(PERL) -MExtUtils::Embed PERL_CFG_CCFLAGS = `$(PERL) $(CONFIG_PM) -e 'print "$$Config{ccflags} +$$Config{cccdlflags}"'` PERL_CFG_ARCHLIB = `$(PERL) $(CONFIG_PM) -e 'print $$Config{archlibexp +}'` PERL_CCFLAGS = -I$(PERL_CFG_ARCHLIB)/CORE $(PERL_CFG_CCFLAGS) $(PERL_H +OOKS) $(TRACE) STATIC_EXTS=Sybase::OpnSrv XS_INIT = `$(EXTUTILS_EMBED) -e xsinit -- -std $(PERL_STATIC_EXTS) $(S +TATIC_EXTS)` CC=`$(PERL) $(CONFIG_PM) -e 'print $$Config{cc}'` LD=`$(PERL) $(CONFIG_PM) -e 'print "$$Config{ld}\n"'` .... SRC=xp_perl.c perlxsi.c ... # other files OBJS=$(SRC:.c=.o) perlxsi.c: $(XS_INIT)
This generates a perlxsi.c file like this:
#include <EXTERN.h> #include <perl.h> EXTERN_C void xs_init (pTHXo); EXTERN_C void boot_Sybase__OpnSrv (pTHXo_ CV* cv); EXTERN_C void boot_DynaLoader (pTHXo_ CV* cv); EXTERN_C void xs_init(pTHXo) { char *file = __FILE__; dXSUB_SYS; newXS("Sybase::OpnSrv::bootstrap", boot_Sybase__OpnSrv, file); /* DynaLoader is a special case */ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); }
which bootstraps all of the static modules when the perl interpreter is started.

Michael


In reply to Re: Embedding Perl Interpreter/DynaLoader by mpeppler
in thread Embedding Perl Interpreter/DynaLoader by MatthewFrancis

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.