Hi, Actually, I think your code doesn't need to be in a subdirectory. It's just that IIRC Inline looks for a slash ('/') to know if the specified scalar is a filename or the source code itself. If you use './myCcode.c' it should work.
But in your case, you should be able to just read in the 2 files yourself and send the code directly to Inline::C like this: #!/usr/bin/perl use strict ; sub get_code { my $code = '' ; for my $src (@_){ $code .= join('', <SRC>) if open(SRC, $src) ; } return $code ; } use Inline( C => get_code(qw(C/myCcode.c C/moreC.c), ) ; or if your are lazier: use Inline( C => scalar `cat C/myCcode.c C/moreC.c` ) ; Patrick On Sun, Mar 30, 2008 at 1:41 PM, second axiom <[EMAIL PROTECTED]> wrote: > > > Sisyphus <[EMAIL PROTECTED]> wrote: > ----- Original Message ----- > From: "second axiom" > > To: > Sent: Sunday, March 30, 2008 3:56 PM > Subject: Inline::C - including an external file and nothing else > > > > Hello. > > > > I'm able to create Perl script that uses Inline C and also links to a > > precompiled C library, but I'm trying to do something else that I think > > should be equivalent: > > > > #!/usr/bin/perl -w > > use Inline C => < > > #include > > > ENDC > > test(2); > > > > I.e., if I paste the contents of myCcode.c in place of the #include, I get > > the expected results. I'm trying to get Inline to do that and ignore the > > fact that the code comes from a separate file, but it refuses to recognize > > the functions in myCcode.c. (Basically, I prefer to avoid compiling the > > code myself.) > > > > I created a file called 'src/myCcode.c' which contained: > > void greet() { > printf("Hello from myCcode.c\n"); > } > > I then ran the following Inline::C script: > > use warnings; > use Inline C => 'src/myCcode.c'; > greet(); > > which, behaved as desired and printed out (after compiling): > > Hello from myCcode.c > > However, for some reason, it seems that myCcode.c needs to be in a > subdirectory. If it's placed in the same directory as the Inline::C script, > it doesn't work. This is mentioned in 'perldoc Inline-FAQ'. > > Cheers, > Rob > > > Hi, Rob. > > Thanks for the reply; let me know if I'm breaking any rules of replies. > > I had indeed tried your suggestion (use Inline C => 'src/myCcode.c';) and > gotten it to work, but my Inline::C script has additional C code that > #include's myCcode.c. I'm able to call the functions in myCcode.c and access > its global vars from Perl and from Inline::C, but the two are operating on > separate instantiations of those variables. > > What I'm trying to accomplish seems to be a combination or modification of > current options, a concatenation of a source file and the Inline::C code I > have in the script: > > use Inline (C => 'C/myCcode.c', <<ENDC); > [new C code here] > ENDC > > OR a concatenation of two source files: > > use Inline (C => 'C/myCcode.c', 'C/moreC.c'); > > (Or both, for that matter.) This would mean that any calls from Perl or from > the Inline::C code would be operating on the same instantiation of the global > variables in C/myCcode.c. This alternative fails, but for another reason: > > use Inline C => <<ENDC, AUTO_INCLUDE => '#include "C/myCcode.c"'; > > OR: > > use Inline C => <<ENDC > #include "C/myCcode.c" > > In both cases, Inline::C can access the functions and vars in myCcode.c, > but Perl cannot. > > It doesn't matter to me if this is accomplished through eval, symbolic > links, whatever. Based on your reply to a previous question, it sounds like I > need to modify C.pm. > > Thanks again. > > AndyD > > > > --------------------------------- > OMG, Sweet deal for Yahoo! users/friends: Get A Month of Blockbuster Total > Access, No Cost. W00t -- ===================== Patrick LeBoutillier Laval, Québec, Canada