What's the best g++ optimization level when building a debug target?

前端 未结 3 1290
Happy的楠姐
Happy的楠姐 2020-12-12 22:34

When you want to build something that\'s debuggable (g++ specifically, but perhaps shares an answer with gcc), what\'s the best -O level? In other words, when building a \"

3条回答
  •  别那么骄傲
    2020-12-12 22:56

    GCC 4.8 introduces a new optimization level: -Og for the best of both worlds.

    -Og
    Optimize debugging experience. -Og enables optimizations that do not interfere with debugging. It should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.

    This way some optimization is done so you get better performance, better possibly-uninitialized variable detection and you can also step through a program in GDB without jumping back-and-forth through the function.

提交回复
热议问题