#!/usr/bin/env perl use strict; use warnings; use ExtUtils::CBuilder; my $cfile = 'hello.c'; (my $objfile = $cfile) =~ s/\.c$/.o/; # warning, it writes C program to your disk open(my $FH, '>', $cfile) or die "could not write C file ($cfile) to disk, $!"; print $FH $_ for(); close($FH); die "failed to write C file ($cfile) to disk." unless -f $cfile; # warning it will produce object file on your disk my $cbuilder = ExtUtils::CBuilder->new( config => { optimize => '-O7', }, ); $cbuilder->compile( source => $cfile, object_file => $objfile ); __DATA__ #include int main(void){ printf("hello\n"); } #### gcc -I/usr/lib64/perl5/CORE -fPIC -c -D_REENTRANT -D_GNU_SOURCE -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O7 -o hello.o hello.c