in reply to Re: External (extra) files when using Inline::CPP
in thread External (extra) files when using Inline::CPP
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.
PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: External (extra) files when using Inline::CPP
by syphilis (Archbishop) on Apr 17, 2024 at 00:36 UTC | |
by swl (Parson) on Apr 17, 2024 at 04:11 UTC | |
by syphilis (Archbishop) on Apr 17, 2024 at 12:39 UTC | |
by cavac (Parson) on Apr 18, 2024 at 06:00 UTC |
In Section
Seekers of Perl Wisdom