Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (None)
    As of 2024-04-25 00:35 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found