Building Yocto* Project Images and Applications from the Command Line

Intel® System Studio provides an integration layer and several recipes to integrate with the Yocto* Project development environment. For more information, see

Using icc in the Yocto Image Build Environment as a Secondary Compiler

When you have used the integration layer to integrate Intel® System Studio, you can build a Yocto image using gcc as the primary compiler, and also use the Intel compiler as a secondary compiler. For example, when building the platform image with gcc, you can include an application, built using the Intel compiler, as part of the image.

To enable the Intel compiler to build a specific package, add the following line in the package recipe .bb file:

TOOLCHAIN_pn-${PN} = "icc"

The Intel® C++ Compiler is now invoked automatically when you use this recipe .bb file to build this package.

App Development: When the Yocto SDK is Built with icc Environment Scripts

When you have used the integration layer to integrate Intel® System Studio when you build the SDK, the Intel compiler build environment script file is automatically generated in the same folder in which the default gcc compiler environment scripts are located.

To set up the Intel compiler build environment and use the Intel compiler for building, source the icc environment script. The icc environment script has the same name as the file for the gcc compiler but with the extension -icc. Sourcing the script overwrites the environment variables CC, CXX, AR and LD. For example, on a Linux system:

source /opt/poky/2.1/environment-setup-i586-poky-linux-icc

Check the content in environment-setup-i586-wrs-icc and update the compiler options if necessary for your compilation.

App Development: When the Yocto SDK is Not Built with icc Environment Scripts

Use the --sysroot option to specify the target root directory of headers and libraries. For example, if the headers and libraries are normally located in /usr/include and /usr/lib respectively, --sysroot=/mydir causes the compiler to search in /mydir/usr/include and /mydir/usr/lib for the headers and libraries.

Use the -gnu-prefix option to specify a string that prepends the name of the GNU tools called from the Intel® C++ Compiler. The value depends on the GNU toolchain used for a particular operating system. For example, for the Yocto* Project v2.1, the prefix value is i586-poky-linux-. Append a hyphen to the prefix only if the toolchain prefix ends with a hyphen.

To adapt the Intel® C++ Compiler to the Yocto* Project v2.1 build environment:

  1. Make a copy of the GCC environment setup file and rename it to environment-setup-i586-poky-linux-icc.

    cp /opt/poky/2.1/environment-setup-i586-poky-linux /opt/poky/2.1/environment-setup-i586-poky-linux-icc 

  2. Open the environment setup file, /opt/poky/2.1/environment-setup-i586-poky-linux-icc, and locate the following build settings:

    export CC="i586-poky-linux-gcc  -m32   -march=i586 --sysroot=/opt/poky/2.1/sysroots/i586-poky-linux"
    export CXX="i586-poky-linux-g++  -m32   -march=i586 --sysroot=/opt/poky/2.1/sysroots/i586-poky-linux"
    export LD="i586-poky-linux-ld   --sysroot=/opt/poky/2.1/sysroots/i586-poky-linux"
    export AR=i586-poky-linux-ar

  3. Change them to:

    export CC="icc -gnu-prefix=i586-poky-linux- -m32 -march=i586 --sysroot=/opt/poky/2.1/sysroots/i586-poky-linux"
    export CXX="icpc -gnu-prefix=i586-poky-linux- -m32 -march=i586 --sysroot=/opt/poky/2.1/sysroots/i586-poky-linux"
    export LD="xild -qgnu-prefix=i586-poky-linux- --sysroot=/opt/poky/2.1/sysroots/i586-poky-linux"
    export AR="xiar -qgnu-prefix=i586-poky-linux-"

  4. Save the file.

To build an application called my_source_file.c, on a Linux* OS host for the Yocto Project* v2.1 target, use the following commands:

source /opt/intel/system_studio_yyyy.x.y/bin/ ia32
source /opt/poky/2.1/environment-setup-i586-poky-linux-icc
$CC my_source_file.c

You can also use icc directly from the command line with the –gnu-prefix and --sysroot compiler options, as follows:

icc –gnu-prefix=i586-poky-linux- --sysroot=/opt/poky/2.1/sysroots/i586-poky-linux my_source_file.c

Following successful compilation, an executable named a.out is created in the current directory. Copy a.out onto the target machine running Yocto* Project (v2.1 in this example), and verify that a.out runs on the target machine.

For information about the gnu-prefix and sysroot compiler options, see the Intel® C++ Compiler 18.0 Developer Guide and Reference.

For more complete information about compiler optimizations, see our Optimization Notice.