When compiling C embeding Perl scripts one is better to use the compilation flags (CFLAGS/LDFLAGS) and compiler suggested by Config and ExtUtils::Embed (which derives them from former) like so:

perl -MConfig -e 'print $Config{cc}' perl -MConfig -e 'print $Config{ccflags}' perl -MExtUtils::Embed -e ccopts -e ldopts

In my system (Config v5.026002, Perl v5.26.2 + updated linux) I have just noticed that suggested CFLAGS include optimisation flags -g -O2 which void completely any optimisation flags I may want to use. For example I was trying to debug a script embeded in a C program and kept getting:

(gdb) print *ret value has been optimized out

Until I realised what was going on and spent another hour trying to remove them using Gnu make's primitive string-substitution options*. I mean, I am not used to tell my computer:

./configure CFLAGS='-g' && make clean && make CFLAGS='-g'

and still to get optimised-out code in the debugger!

Should this behaviour be filed as a bug with Config and if yes, where does one file bugs for that module?

bw, bliako

*) To cut my losses I finally resorted to gsed rendering my dist completely un-portable. Perl should be better choice.

Update:I will mention that there is an m4 macro which returns Perl's compiled CFLAGS etc. This is in the case when one has a C project which embeds a Perl interpreter and one does not want to use a Perl Makefile.PL but want to use Gnu Autotools. So the macro is AX_PERL_EXT (https://www.gnu.org/software/autoconf-archive/ax_perl_ext.html). When one uses it in a configure.ac file like AX_PERL_EXT(0.0) various variables will be created like PERL_EXT_LDFLAGS which one can use in the various Makefile.am of the project. Based on that macro, other macros can be created to filter out unwanted optimisations inside the Perl oneline, thus avoiding the need to do string substs using Makefile ancient ways. It was a long learning curve so I thought it's worth "polluting" this little corner of the Monastery.


In reply to Config sets optimisation compilation flags (-O/-g)! 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.