zephyr-rtos

In zephyr-rtos, how to set compilation `-O0` flags at build time?


In zephyr-rtos, how to set compilation -O0 flags at build time?

I'am new to both embedded/rtos dev and zephyr. Following the official zephyr doc, I managed to install zephyr/west and build/flash/run the blinky example that works from-debian-on-the-board.

Following the doc, west debug runs fine but it seems the build is done in RelWithDebInfo by default so the gdb doesn't have all infos at debug time.

How to pass -O0 at build time to get full scope debugging latter on with west debug?


Solution

  • To set -O0, you can provide the KConfig CONFIG_NO_OPTIMIZATIONS option to west. Command for blinky sample application:

    west build samples/basic/blinky -CONFIG_NO_OPTIMIZATIONS=y
    

    For debugging, -Og might be a better choice:

    west build samples/basic/blinky -DCONFIG_DEBUG_OPTIMIZATIONS=y
    

    You can set the KConfig option also in prf.conf of your app. For the blinky sample set DCONFIG_DEBUG_OPTIMIZATIONS=y in zephyr/samples/basic/blinky/prj.conf.

    See also KConfig search documentation.