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

Monks,
I did in fact come up with a way to call a function written in C from a Perl script using Inline. See below for the C source code and the Perl script:
#include <stdio.h> int x; int sum; int main() { pure_c(); return (0); } pure_c() { for (x = 0; x < 100; ++x) { sum = sum + x; printf("%d\n", sum); } return (0); } /* end of pure_c */ #!/usr/local/perl/5.6.1.4/bin/perl -w use ConsistentSet "1.0.2"; # This finds the library Inline no AutoLoader; use Inline C => 'DATA'; c_wrapper(); __DATA__ __C__ #include "c_test.c" int c_wrapper() { pure_c(); printf("After pure_c\n"); return (0); }

Thanks to all who gave comments and suggestions!! :)
***ginttu***

Replies are listed 'Best First'.
Re: Inline::C Resolution
by Courage (Parson) on Dec 03, 2002 at 07:53 UTC
    Well, your code seems to work okay.
    What do you want to ask?

    A couple of further guildelines from me before I wish you good wishes to your investigations:

    • subscribe to "Inline" mailing list
    • remove those use ConsistentSet ...; and no AutoLoader; and configure your system to find needed resources appropriately
      (as I did before running your code)
    • be brave

    Courage, the Cowardly Dog