I want to run a script at computer, where I'd rather not expose its (this script's) C guts (embarrassing situation... sorry). Consider SSCCE of myscript.pl:

use strict; use warnings; use feature 'say'; use Inline C => << 'END'; int add (int x, int y) { return x + y; } END say add( 5, 7 );

I know nothing about XS; and (another alternative) though I think I can compile C to a DLL and then use FFI, I suspect it would be less efficient: script is run many times -- as e.g. $^X myscript.pl -- by larger continuously running Perl application. So I'd prefer to stay with Inline::C, but 'hide' the algo realisation.

There's FAQ topic, but it's (1) not exactly about what I need, and thus not achieves what I want, (2) I found it's not exact in what it describes -- no need to split Perl and C into separate files, no need to bother with MD5.

Nevertheless, using FAQ as base and example Math::Simple bundled with Inline:

mkdir MyC, place 2 files there:

Makefile.PL:

use Inline::MakeMaker; WriteMakefile( NAME => 'myC', VERSION_FROM => 'myC.pm' );

myC.pm:

package myC; our $VERSION = 1; use Inline C => << 'END', VERSION => 1, NAME => 'myC'; int add (int x, int y) { return x + y; } END 1;

then run perl Makefile.PL, gmake test. The blib directory is created, where I can delete everything but 2 files:

blib/arch/auto/myC/myC.xs.dll

blib/lib/myC.pm

the latter I modify as ('END' can be anything, no need to write MD5):

package myC; our $VERSION = 1; use Inline C => 'END', VERSION => 1, NAME => 'myC'; 1;

Then I modify original myscript.pl as:

use strict; use warnings; use feature 'say'; use blib; use myC; say myC::add( 5, 7 );

Then move it to some other location for testing, bundled with blib folder (which itself is 4 folders, 2 files). Looks like goal achieved, but I wonder if there is 'more correct' way. In particular, I'd like to avoid creating dummy module and package (myC), or at least have it declared inside myscript.pl itself. 2nd point, I'd like the dll to be placed e.g. into "standard" _Inline directory with "standard" Inline hierarchy and naming conventions, since this folder already exists anyway (for parts which I don't bother to 'hide'. Like I said the whole situation is complicated and embarrassing), so there's no need to use blib;. Maybe there are Inline configuration options for that?


In reply to Better way to force Inline to use compiled binary instead of C source? by vr

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.