5

I use meson 0.53.2 on ubuntu 20.04.
I would like to have a maximally optimized executable (-Ofast) but contain all debug symbols (-g3)

  • If I use --buildtype=release it optimizes -O2 and the executable contains no debug symbol.
  • If I use --buildtype=debug it does not optimize at all and uses -g.
  • If I use --buildtype=debugoptimized it optimizes -O2 and uses -g.

I tried to use --debug which seems not to work, because the executable does not contain any debug symbol. Instead if I use -Ddebug=true the debug symbols are there but with the flag -g.

So how do I get gcc to compile with -Ofast -g3 flags in the least dirty way possible?

mastupristi
  • 1,240
  • 1
  • 13
  • 29
  • Your best bet is to stick to `debugoptimized`, see [this SO question](https://stackoverflow.com/questions/7493947/whats-the-best-g-optimization-level-when-building-a-debug-target) on the why – nielsdg Nov 12 '20 at 21:51
  • 1
    @nielsdg I do not want it to be debuggable at all. I need few things, one among all the stack trace. But it is absolutely necessary that the optimization is `-Ofast`. If I use `dubugoptimized` the optimization is only `-O2`. – mastupristi Nov 15 '20 at 20:15

1 Answers1

0

From the commandline, you can switch higher level of optimization with option optimization=3. It gives you -O3 instead -O2.

By editing meson script, you can set any flags.

if get_option('buildtype') == 'custom'
  add_project_arguments('-Ofast', '-g3',  language : 'cpp')
endif

And in case you cannot modify meson script, you may alter environment variables

CXXFLAGS="-Ofast -g3" meson --buildtype=custom build_c

And --reconfigure seems to not see environment variables.

Askold Ilvento
  • 1,405
  • 1
  • 17
  • 20