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

Don't ask me why, but the boss wants it this way :)

I have a perl program I need to turn it into C, I did this

with: perl -MO=C fred.pl > fred.c

Worked great, now does anyone know how to compile the
thing under C to a exec.?

I tried: cc fred.c > fred

With no luck, not finding includes
EXTERN.h No such file or directory
perl.h No such file or directory

I can find them on the HD, but how do I add the paths to the cc command line?

Thanks,
Steve

Replies are listed 'Best First'.
Re: Translating Perl to C
by plaid (Chaplain) on Jun 27, 2000 at 22:31 UTC
    First off, you don't want to redirect the output to fred, you want to specify it as the output file. Secondly, you can specify include directories on the command line with the -I flag. Try

    cc -I/path/to/includes -o fred fred.c

Re: Translating Perl to C
by btrott (Parson) on Jun 27, 2000 at 22:39 UTC
    Those are the CORE Perl include files that your script is including. This should be discussed in the docs for the compiler, I'm sure, but you should add the path to those include files as a -I arg to cc. You *should* have those files. Look around in @INC to try and find them. They'll be in something like
    /usr/lib/perl5/<arch>/<version>/CORE
    where <arch> is your architecture, and <version> is your Perl version.

    So you'd do something like

    % cc -I /usr/lib/perl5/<arch>/<version>/CORE fred.c
    I think.
Re: Translating Perl to C
by Aighearach (Initiate) on Jun 28, 2000 at 09:37 UTC
    Perl is written in C. What does this mean? it means Perl is a meta-language for C. Toss that at your boss. The word meta always dazzles the suits. Or dazes. Anyway, just explain that it is already is written in C.
    Paris Sinclair    |    4a75737420416e6f74686572
    pariss@efn.org    |    205065726c204861636b6572
    I wear my Geek Code on my finger.
    
Re: Translating Perl to C
by Ovid (Cardinal) on Jun 27, 2000 at 23:18 UTC
    I've tried this one some of my Perl scripts and came away with a bloated, unmaintainable mess. In looking through that mess (and that required a strong stomach, believe me), I see that it's still dependant upon Perl. Therefore, I can't help but wonder how efficient this C is compared to the equivalent Perl (mod perl may be a better comparison).
      B::CC is a little better. It produces slightly more idiomatic code.

      I wouldn't use it in a production environment, though. The only time I've ever compiled Perl was using perl2exe, and that was simply a one-shot filter application that had to be run on a completely different platform approximately once every three weeks.

      Most of these 'compilers' just produce a wrapper around a working Perl environment, anyway. How else would they handle eval()?

      This is because the perl to c conversion actually embeds the perl compiler with everything else, and then uses it to compile your perl script at runtime... all within one executable. It's sick but it works.