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


In reply to ExtUtils::CBuilder->compile() ignores flags by bliako

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.