Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Using multiple Inline::C files

by gri6507 (Deacon)
on Feb 13, 2014 at 15:22 UTC ( [id://1074849]=perlquestion: print w/replies, xml ) Need Help??

gri6507 has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks, I have a script which uses Inline::C to pull in several files. Currently it looks like this.
use warnings; use strict; use File::Spec; use File::Basename; my $inlineCFile; my $inlineCFile2; my $relSourcePath; my $inlineBuildDir; my $libDir; my $incDir; BEGIN { $relSourcePath = File::Spec->rel2abs(dirname($0)); $inlineCFile = File::Spec->catfile($relSourcePath, "foo.c"); $inlineCFile2 = File::Spec->catfile($relSourcePath, "bar.c"); my @dirs = (); push @dirs, $relSourcePath; push @dirs, ".Inline"; $inlineBuildDir = File::Spec->catdir(@dirs); pop @dirs; push @dirs, "lib"; $libDir = File::Spec->catdir(@dirs); pop @dirs; push @dirs, "include"; $incDir = File::Spec->catdir(@dirs); } use Inline ( C => Config => LIBS => "-L$libDir", INC => "-I$incDir", DIRECTORY => $inlineBuildDir, ); use Inline C => $inlineCFile; use Inline C => $inlineCFile2; HelloFoo(); HelloBar();
where, for the sake of this question, foo.c is
void HelloFoo() { printf("hello from foo\n"); }
and bar.c is
void HelloBar() { printf("hello from bar\n"); }
Now, let's say that I want to pull in many more such Inline::C files into my script. Is there a better way than the individual scalar definition for each C file inside the BEGIN block followed by the individual use Inline::C => $myFile?

Replies are listed 'Best First'.
Re: Using multiple Inline::C files
by tilly (Archbishop) on Feb 13, 2014 at 15:51 UTC
    Have an array of files. And then call import in a loop to load those files.
    for my $file (@files) { Inline->import("C", scalar File::Spec->catfile($relSourcePath, $file)); }
      Thank you. That's exactly what I was looking for.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1074849]
Approved by toolic
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-19 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found