bliako has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks, I wonder if what I see is a bug or it is a mistake on my part:
The following script will attempt to compile and link a sample C file (warning: it writes what's in __DATA__ as a file on your current dir) using ExtUtils::CBuilder. However, the compile() sub ignores the optimize flags I try to set. Basically I want to remove -g.
#!/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 d +isk, $!"; print $FH $_ for(<DATA>); 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 <stdio.h> int main(void){ printf("hello\n"); }
What I get (in linux, perl v 5.26.2, ExtUtils::CBuilder 0.280230) is compile() uses its own optimization (-O2 -g) and also mine (-O7):
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 -fexcept +ions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc- +switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=g +eneric -fasynchronous-unwind-tables -fwrapv -fno-strict-aliasing -I/u +sr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O7 -o he +llo.o hello.c
bw, bliako
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: ExtUtils::CBuilder->compile() ignores flags
by choroba (Cardinal) on Jan 04, 2019 at 18:41 UTC | |
by bliako (Abbot) on Jan 04, 2019 at 19:22 UTC |