You can use the Intel® C++ Compiler 16.0 to develop 32-bit and 64-bit applications for Intel® architecture-based devices.

This guide refers to the Intel® C++ Compiler as the compiler, or icc.

Android Targets

Just about anything you can do in your gcc source code for your Android applications, you can also do with the Intel C++ Compiler. You can even build applications that use gcc for devices based on ARM* Architecture and the Intel compiler for devices based on Intel® architecture. The Intel compiler is highly compatible with gcc and tools in the NDK and SDK, while delivering outstanding application performance.

The Intel C++ Compiler requires the Android NDK.

The Android NDK ships with sample applications that can be found in the samples directory under the installed Android NDK directory. This guide shows how to start building for an Android* target using the hello-jni sample application shipped with the Android NDK.

Prerequisites

Set up the Intel compiler environment with the following command:

For Windows 32-bit targets: "<compiler-install_dir>\bin\compilervars.bat -arch ia32" -platform android

For Linux 32-bit targets: $ source <compiler-install_dir>/bin/compilervars.sh -arch ia32 -platform android

For Windows 64-bit targets: "<compiler-install_dir>\bin\compilervars.bat -arch intel64" -platform android

For Linux 64-bit targets: $ source <compiler-install_dir>/bin/compilervars.sh -arch intel64 -platform android

For details on compilervars, refer to Using compilervars File in the Intel® C++ Compiler 16.0 User and Reference Guide.

Using the Compiler with Eclipse*

This section explains how to configure Eclipse and Eclipse projects to use and build with icc using the Android Native Developer Kit (NDK) r10c-r10e. The Android NDK is a toolset that allows you to compile those parts of your application that use native-code languages such as C and C++.

Before using Eclipse to develop Android applications, Eclipse must be integrated with the Android Developer Toolkit (ADT) plugin. The ADT includes SDK components and a version of the Eclipse IDE with built-in Android Developer Tools. For more information on ADT, see http://developer.android.com/tools/help/adt.html.

Note

The ADT does not support NDK revisions later than r10e.

If you install Intel® System Studio after installing the Android NDK, the Android NDK is integrated automatically. If you install the NDK after installing Intel® System Studio, run the integration script ndk_integration.sh (Linux hosts) or ndk_integration.cmd (Windows hosts),  at <install_directory>/toolchains.

  1. Configure Eclipse to use the NDK plugin. Select Window > Preferences.

  2. In the Preferences window, select Android > NDK. Enter the NDK path in the NDK Location text box and click OK.

  3. Create a new project from the NDK samples. Select File > New > Project…. The New Project dialog box appears.

  4. Select Android Project from Existing Code and click Next.

    The Import Project window opens.

  5. Browse to hello-jni in the NDK samples directory. Confirm the project you want to load, check Copy projects into workspace, and then click Finish.

    The newly created project opens in the Project Explorer.

  6. Configure the project to include Native Support, which adds Java and C/C++ support:

    1. Right-click on the project name in the Project Explorer window and select Android Tools > Add native Support....

    2. A dialog opens asking for the Library Name. Set the library name to hello-jni and click Finish.

  7. Open or create a new file named Application.mk in the jni folder with the following lines:

    • For 32-bit targets:

      APP_ABI:=x86
      NDK_TOOLCHAIN:=x86-icc
    • For 64-bit targets:

      APP_ABI:=x86_64
      NDK_TOOLCHAIN:=x86_64-icc
  8. To build your project, right-click on the project name in the Project Explorer and select Build Project.

You can test the application on any Intel architecture-based Android device including an Android Virtual Device.

Using the Compiler with vs-android in Visual Studio*

The vs-android plugin supports Visual Studio* 2010, 2012 and 2013. Visual Studio* 2015 includes built-in support for developing Android* applications and does not require the vs-android plugin.

The Intel® product installation integrates the Intel® compiler with vs-android, so you can use Visual Studio* to build your Android applications immediately.

If you installed the vs-android plugin after installing Intel® System Studio, see Microsoft* Visual Studio* IDE: vs-android Support for Building Android* Applications in the Intel® C++ Compiler 16.0 User and Reference Guide Supplement for Intel® System Studio 2016 for information on adding the vs-android integration.

  1. Create a Visual C++ project, or open an existing project.

  2. In Solution Explorer, select a project to build with the Intel® C++ Compiler.

  3. Select Project > Properties to open the Property Pages.

  4. In the Property Pages, select Configuration Manager.

  5. In the Active solution platform list, select New.

  6. In New Solution Platform, select the platform Android and click OK.

  7. Select Configuration Properties > General. Under Platform Toolset, select one of the available x86 icc toolchains.

    Notice that the list of available toolsets contains a corresponding toolset for each installed Intel® C++ Compiler.

  8. Under the Project Defaults property list, change Target Architecture to x86 Architecture (x86).

  9. Click OK to save and close the Property Pages.

Selecting this toolset ensures that Intel® C++ Compiler is used for building your projects. Check the display of Intel-specific property pages and properties.

You can now proceed to use the Intel® Compiler to build Android* applications with Microsoft Visual Studio*. For details, check Visual Studio* documentation on www.microsoft.com.

Building Android* Applications with Visual Studio* 2015

Microsoft* Visual Studio* 2015 includes built-in support for developing Android applications. You do not need to use the vs-android plugin.

To develop Android* applications with Visual Studio* 2015, you must install the optional components that enable cross platform support. For more information, see Building Android* Applications Using Microsoft* Visual Studio* 2015 in the Intel® C++ Compiler 16.0 User and Reference Guide

To build Android* applications using the Intel® C++ Compiler from within Visual Studio* 2015:

  1. Create a Visual C++ project using one of the marked cross platform templates for Android cross platform development. In the New Project dialog go to Templates > Other Languages > Visual C++ > Cross Platform, choose one of the marked templates and enter a name, location, and solution name to create a new project.

  2. Click OK to close the New Project dialog.
  3. In the Solution Explorer, select the project that you want to build with the Intel® C++ Compiler.
  4. Go to Project > Properties. The Property Pages dialog opens.
  5. Select Configuration Properties > General category. Under General property list, change Platform Toolset to Intel C++ Compiler 16.0.

  6. Click OK to save and close the Property Pages dialog.

You are ready to build native Android* applications in Visual Studio* 2015 using the Intel® C++ Compiler.

Using the Command Line

You can build applications for Intel architecture-based Android devices in two ways. You can enable the icc toolchain with the Android NDK build system or you can use the icc toolchain as a standalone compiler. The following sections provide general guidelines for each method.

The Intel compiler is not the default compiler for Intel architecture-based targets for the Android NDK r10 and later.

To build an application with the Intel® C++ Compiler 16.0 toolchain using the Android NDK r10 and later, do one of the following:

  • Explicitly pass to ndk-build: NDK_TOOLCHAIN=x86-icc (for 32-bit targets) or NDK_TOOLCHAIN=x86_64-icc (for 64-bit targets)
  • In the application configuration file (Application.mk) set NDK_TOOLCHAIN=x86-icc (for 32-bit targets) or NDK_TOOLCHAIN=x86_64-icc (for 64-bit targets)

The Android NDK ships with sample applications that can be found in the samples directory in the Android NDK installation directory.

Using the icc toolchain with the Android NDK Build System

Use the hello-jni sample application that ships with the Android NDK.

Use the command-line to navigate to the jni folder in the sample and enter one of the following commands:

  • For 32-bit targets:

    Linux host: $NDK_DIR/ndk-build APP_ABI=x86 NDK_TOOLCHAIN:=x86-icc

    Windows host: %NDK_DIR%\ndk-build V=1 -B APP_ABI = x86 NDK_TOOLCHAIN:= x86 -icc

  • For 64-bit targets:

    Linux host: $NDK_DIR/ndk-build APP_ABI=x86_64 NDK_TOOLCHAIN:=x86_64-icc

    Windows host: %NDK_DIR%\ndk-build V=1 -B APP_ABI = x86_64 NDK_TOOLCHAIN:= x86_64 -icc

You can specify compiler options in jni/Android.mk. For example:

-ipo -O3 -no-prec-div

For details on compiler options, refer to Compiler Options in the Intel® C++ Compiler 16.0 User and Reference Guide.

Using the icc toolchain as a Standalone Compiler

You can now use icc to compile C source code and icpc to compile C++ source code. For example:

                                                        >>cd $NDK_DIR/samples/hello-jni/jni
                                                        >>cd %NDK_DIR%\samples\hello-jni\jni
>>icc -c hello-jni.c
>>icc -shared -o libhello-jni.so hello-jni.o
                                                

Linux Targets

Prerequisites

Run compilervars.sh (Linux hosts) or compilervars.bat (Windows hosts) to set environment variables that define the location of compiler-related components.

For example, the following command sets up the Intel compiler environment for 32-bit targets with the following command on a Windows host:

"<compiler-install_dir>\bin\compilervars.bat" -arch ia32 -platform linux

ia32 sets up the environment for 32-bit targets. Use intel64 for 64-bit targets.

See Using compilervars File in the Intel® C++ Compiler 16.0 User and Reference Guide for more information.

Using the Compiler with Eclipse*

The Intel® System Studio installation automatically integrates the Intel® C++ Compiler into a preexisting Eclipse* CDT installation. If you install Eclipse after Intel® System Studio, you can integrate the compiler using Help > Install New Software in Eclipse. For more information, see Adding the Compiler to Eclipse in the Intel® C++ Compiler 16.0 User and Reference Guide.

For information on which versions of Eclipse are supported refer to the Intel® System Studio Release Notes.

Follow these steps to select an existing environment file to be used with the active configuration of a current project:

  1. In Eclipse, select a project in the Project Explorer.

  2. Select Intel® System Studio > Compiler Cross-Build Environment File > Select File for <project name>. The Select an Environment File dialog opens.

  3. Use Browse to locate the appropriate environment file. You can find preconfigured ones in <install_directory>\bin\intel64.

  4. Select Apply to All Configurations to use the file for all configurations in the current project.

  5. Click OK to close the dialog.

  6. Select Project > Build Project.

For detailed information on using the compiler with Eclipse, see Using Eclipse in the Intel® C++ Compiler 16.0 User and Reference Guide.

Using the Command Line

The icc command invokes the C compiler. The icpc command invokes the C++ compiler.

Use the --sysroot and -gnu-prefix compiler options together. This section uses a Yocto* project as an example. For details on building for other Linux targets, see the Intel® C++ Compiler 16.0 User and Reference Guide Supplement for Intel® System Studio 2016 .

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 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 v1.4, the prefix value is i586-poky-linux-. Append a hyphen to the prefix only if the toolchain prefix ends with a hyphen.

To adopt the Intel® C++ Compiler (icc) to the Yocto* Project v1.4 build environment, follow these steps:

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

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

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

    export CC="i586-poky-linux-gcc  -m32   -march=i586 --sysroot=/opt/poky/1.4/sysroots/i586-poky-linux"
    export CXX="i586-poky-linux-g++  -m32   -march=i586 --sysroot=/opt/poky/1.4/sysroots/i586-poky-linux"
    export LD="i586-poky-linux-ld   --sysroot=/opt/poky/1.4/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/1.4/sysroots/i586-poky-linux"
    export CXX="icpc -gnu-prefix=i586-poky-linux- -m32 -march=i586 --sysroot=/opt/poky/1.4/sysroots/i586-poky-linux"
    export LD="xild -qgnu-prefix=i586-poky-linux- --sysroot=/opt/poky/1.4/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* [v1.4 or later] target, use the following commands:

source /opt/intel/system_studio_yyyy.x.y/bin/compilervars.sh ia32
source /opt/poky/1.4/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/1.4/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 1.4 or later, and verify that a.out runs on the target machine.

Training and Documentation

Document Description

Online Training

The online training site is an excellent resource for training on using the compiler: https://software.intel.com/en-us/intel-system-studio-support/trainings

Release Notes

Information on the product installation, new and changed features, and issues that are not described in the product documentation.

Intel® C++ Compiler 16.0 User and Reference Guide Supplement for Intel® System Studio 2016

Information specific to this product.

Intel® C++ Compiler 16.0 User and Reference Guide

How to compile and optimize your application by using optimization tools and other libraries.

Samples

Online Intel® C++ Compiler code samples - https://software.intel.com/en-us/code-samples/intel-c-compiler

NDK documentation

Detailed information on the Android NDK. Located in the NDK installation folder under docs.

Using Intel® C++ Compiler for Android* in the Microsoft* Visual Studio*

How to build Android-targeted applications in the Microsoft* Visual Studio* IDE.

Using Advanced Intel® C++ Compiler Features for Android* Applications

How to use Intel® Cilk™ Plus Runtime on Android* to multithread your application and how to use Profile-guided Optimization (PGO) to Improve Android* OS Application Performance.

Building Native Android* Apps Using Intel(R) C++ Compiler in Android Studio*

For the current status of Android Studio support. Android Studio support is a preview feature.

Web Resources

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