How to add global CXX compiler flag to yocto build

17,720

Solution 1

You can add global compiler options for Yocto builds in poky/meta/conf/bitbake.conf. After adding options, check the bitbake environment using the command bitbake -e

cat poky/meta/conf/bitbake.conf

...
...
##################################################################
# Build flags and options.
##################################################################

export BUILD_CPPFLAGS = "-isystem${STAGING_INCDIR_NATIVE}"
BUILDSDK_CPPFLAGS = "-isystem${STAGING_INCDIR}"
export CPPFLAGS = "${TARGET_CPPFLAGS}"

export BUILD_CFLAGS = "${BUILD_CPPFLAGS} ${BUILD_OPTIMIZATION}"
BUILDSDK_CFLAGS = "${BUILDSDK_CPPFLAGS} ${BUILD_OPTIMIZATION}"
export CFLAGS = "${TARGET_CFLAGS}"
export TARGET_CFLAGS = "${TARGET_CPPFLAGS} ${SELECTED_OPTIMIZATION}"

export BUILD_CXXFLAGS = "${BUILD_CFLAGS}"
export CXXFLAGS = "${TARGET_CXXFLAGS}"
export TARGET_CXXFLAGS = "${TARGET_CFLAGS}"

Solution 2

You can add it to the machine configuration file.

The machine configuration file is in the board support layer, under conf/machine. It is named $MACHINE.conf, where MACHINE is defined in your local.conf.

Here are the ones in poky 1.4. Yours might be in a layer outside of poky.

> ls -1 meta-yocto-bsp/conf/machine/
atom-pc.conf
beagleboard.conf
mpc8315e-rdb.conf
routerstationpro.conf
> ls -1 meta/conf/machine/
include
qemuarm.conf
qemumips.conf
qemuppc.conf
qemux86-64.conf
qemux86.conf

Once you identify your board configuration file, add a line to the end to add to your C Flags:

TARGET_CFLAGS += " <my flags> "
Share:
17,720
Waldorf
Author by

Waldorf

Updated on June 04, 2022

Comments

  • Waldorf
    Waldorf almost 2 years

    It seems something obvious to me, but I couldn't find any solution. Suppose I want to add or change a compiler flag/option which applies to all yocto recipes. It is possible to add a global flag somewhere, without changing the recipes ?