Perfect, thank you!
I ended up with doing some extra magic in BEGIN, to automate those compile steps (.cpp and .h files in same directory):
#!/usr/bin/env perl
use v5.38;
use strict;
use warnings;
use Carp;
use Cwd;
use Array::Contains;
my $dir;
my $verbose;
BEGIN {
$dir = getcwd;
print "Working directory: $dir\n";
$verbose = 0;
if(contains('-v', \@ARGV)) {
$verbose = 1;
}
# ---- Poor mans Makefile ---
if(contains('--clean', \@ARGV)) {
print "Cleaning up\n";
my $cmd = 'rm -rf _Inline xkcd.o libxkcd.a';
print "$cmd\n" if($verbose);
`$cmd`;
exit(0);
}
print "Compiling library...\n";
foreach my $cmd ('g++ -c xkcd.cpp', 'ar -rc libxkcd.a xkcd.o') {
print "$cmd\n" if $verbose;
`$cmd`;
}
# ---- Poor mans Makefile ---
};
use Inline 'CPP';
use Inline CPP => Config =>
BUILD_NOISY => $verbose,
INC => '-I' . $dir,
LIBS => '-L' . $dir . ' -lxkcd',
;
for(1..3) {
print "XKCD Dice roll: ", cast_die(), "\n";
}
__END__
__CPP__
#include "xkcd.h"
int cast_die() {
int rolled = xkcd_dice_roll();
return rolled;
}
Hmm, i also tested without the empty lines at the bottom of the files and it worked fine. But i dimly remember having the same (or similar) issue to yours on another project.
-
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.
|