I'm exploring ways to build a plugin system for an existing large C++ program. Embedding perl might be one good way to achieve this. The embedded perl could eval user code/modules to alter behavior.

However, it's absolutely critical that the user plugins can bring compiled code with them, i.e. code that is not already linked in the executable. Plugins would occasionally be doing some computationally intensive stuff internally where pure Perl wouldn't cut it. Is this possible?

My understanding is that to use object code from the perl hosting process you have to generate the xs_init code and link in the resulting object file. Is there some black magic way to support this by manually hacking the xs_init? No multi-process solutions are acceptable, though the perl hosting process is free to re-exec itself during some initialization stage; all the plugins to use would be known at start-up.

This might boil down to more of an operating systems question than a Perl question. Are there any ways to tell an executable to arbitrarily "load" an object file? DLL-Injection/LD_PRELOAD? I'm fairly ignorant of these things, if you can't tell.


In reply to Can arbitrary XS/SWIG using modules be loaded into an embedded perl at runtime? by kingkongrevenge

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.