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