Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Maybe it's a capability within Inline::Module?

Quite likely, assuming that it's using Inline solely for the generation of the XS file, and not the generation of the Makefile.PL.
For generation of XS files I use InlineX::C2XS/InlineX::CPP2XS - both of which also have the capability of generating a Makefile.PL with the OBJECT=>'$(O_FILES)' argument to WriteMakefile()).

The problem with Inline::C and Inline::CPP is that, for the OBJECT=>'$(O_FILES)' approach to work, the .c or .cpp file(s) (xkcd.cpp, in this case) needs to be in the build directory.
However, one doesn't know in advance the location of the directory in which the build will actually take place.

There's only a couple of simple hacks to C.pm and CPP.pm needed to enable the passing of the the OBJECT=>'$(O_FILES)' argument to the Makefile.PL that Inline generates in the build directory.
And I've found that those rough hacks work fine so long as xkcd.cpp and xkcd.h have been placed in the build directory before test.pl is executed.

The rough hack I used:
In Inline/C.pm locate and replace
croak "'$key' is not a valid config option for $class\n";
with:
croak "'$key' is not a valid config option for $class\n" unless $key eq 'OBJECT';
In Inline/CPP.pm apply this patch:
--- CPP.pm_orig 2019-04-20 00:50:28.000000000 +1000 +++ CPP.pm 2024-04-17 21:16:22.142182800 +1000 @@ -114,6 +114,9 @@ while (@config_options) { my ($key, $value) = (shift @config_options, shift @config_options +); $key = uc $key; + if ($key eq 'OBJECT') { + $o->{ILSM}{MAKEFILE}{OBJECT} = $value; + } if ($key eq 'NAMESPACE') { _handle_namespace_cfg_option($o, $value); }
I slightly alter test.pl to be:
use Inline CPP => Config => BUILD_NOISY => 1 CLEAN_AFTER_BUILD => 0, OBJECT => '$(O_FILES)', ; use Inline CPP; for(1..3) { print "Perfect random number: ", cast_die(), "\n"; } __END__ __CPP__ #include "xkcd.h" int cast_die() { int rolled=xkcd_dice_roll(); return rolled; }
Then I run perl test.pl, which fails because of an undefined reference to xkcd_dice_roll()
Then remove all files from the build directory (./_Inline/build/test_pl_b6be).
Then copy xkcd.h and xkcd.cpp to the build directory (./_Inline/build/test_pl_b6be).
Then re-run perl test.pl - which succeeds this time.
On inspecting the build directory (./_Inline/build/test_pl_b6be), I can see that xkcd.cpp has been compiled into xkcd.o, and there is no library.
I don't recommend doing it this way - it's more just a proof of concept that this approach could be made to work.

Cheers,
Rob

In reply to Re^5: External (extra) files when using Inline::CPP by syphilis
in thread External (extra) files when using Inline::CPP by cavac

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, 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, 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.
  • 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 drinking their drinks and smoking their pipes about the Monastery: (4)
    As of 2024-07-17 22:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.