Intel® System Studio 2018: Getting Started with the Intel® C++ Compiler 18.0 for Linux* and Android* Targets

You can use the Intel® C++ Compiler 18.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® C++ 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 sample applications are available on GitHub. This guide shows how to start building for an Android* target using the hello-jni sample application. For more information, see the GitHub web site at https://github.com/googlesamples/android-ndk/

Prerequisites

Set up the Intel compiler environment with the following command:

For Windows hosts: "<install-dir>\bin\compilervars.bat -arch intel64" -platform android

For Linux hosts:

  • Dash or other POSIX-compliant shell: $ . <install-dir>/bin/compilervars.sh <arg> -platform android

  • C shell: $ source <install-dir>/bin/compilervars.csh <arg> -platform android

  • Bash shell:

    • $ source <install-dir>/bin/compilervars.sh <arg> -platform android

    • $ . <install-dir>/bin/compilervars.sh <arg> -platform android

where <install-dir> is the top-level installation directory, and <arg> is an argument specifying the target architecture. Use either ia32 or intel64.

For details on compilervars, refer to Specifying Location of Compiler Components with compilervars File in the Intel® C++ Compiler 18.0 Developer Guide and Reference Supplement for Intel® System Studio 2018

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.

To build an application with the Intel® C++ Compiler 18.0 toolchain using the Android NDK, 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 has sample applications that can be found on GitHub. For more information, see the GitHub web site at https://github.com/googlesamples/android-ndk/

Using the icc toolchain with the Android NDK Build System

Use the hello-jni sample application available on GitHub. Download it and unzip it to a directory named samples under the NDK directory. For more information, see the GitHub web site at https://github.com/googlesamples/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 18.0 Developer Guide and Reference.

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:

Linux:
>>cd $NDK_DIR/samples/hello-jni/jni

Windows:
>>cd %NDK_DIR%\samples\hello-jni\jni

>>icc -gnu-prefix=$GNU_PREFIX --sysroot=$SYSROOT -c hello-jni.c
>>icc -gnu-prefix=$GNU_PREFIX --sysroot=$SYSROOT -shared -o libhello-jni.so hello-jni.o
                                                

Note

Starting with Android NDK r16, you must specify -D__ANDROID_API__=<API version> for the compile stage as follows:

>>icc -gnu-prefix=$GNU_PREFIX --sysroot=$SYSROOT -D__ANDROID_API__=<API version> -c hello-jni.c
>>icc -gnu-prefix=$GNU_PREFIX --sysroot=$SYSROOT -shared -o libhello-jni.so hello-jni.o

For more details, see Unified Headers at https://android.googlesource.com/platform/ndk/+/ndk-release-r16/docs/UnifiedHeaders.md .

Linux Targets

Prerequisites

Set up the Intel compiler environment with the following command:

For Windows hosts: "<install-dir>\bin\compilervars.bat -arch intel64" -platform linux

For Linux hosts:

  • Dash or other POSIX-compliant shell: $ . <install-dir>/bin/compilervars.sh <arg>

  • C shell: $ source <install-dir>/bin/compilervars.csh <arg>

  • Bash shell:

    • $ source <install-dir>/bin/compilervars.sh <arg>

    • $ . <install-dir>/bin/compilervars.sh <arg>

where <install-dir> is the top-level installation directory, and <arg> is an argument specifying the target architecture. Use either ia32 or intel64.

For details on compilervars, refer to Specifying Location of Compiler Components with compilervars File in the Intel® C++ Compiler 18.0 Developer Guide and Reference Supplement for Intel® System Studio 2018

Using the Compiler with Eclipse*

The Intel® System Studio installation automatically integrates the Intel® C++ Compiler into a preexisting Eclipse* CDT installation. For information on which versions of Eclipse* are supported, see the Intel® System Studio Release Notes.

To set up the cross-build options for embedded Linux* targets, follow these steps:

  1. In Eclipse, select File -> New -> Project.

  2. Select Application Development -> Project to cross-compile for Linux and Android targets.

  3. Specify the configuration for cross compilation (Yocto 2.2 is used as an example):



  4. Finish creating the project.

  5. Build the project.

You can modify cross-compilation settings later in Project Properties:

  1. Select a project in the Project Explorer and open Project/Properties.

  2. To change the GNU toolchain path select C/C++ Build -> Environment and modify the GNU_CROSS_TOOLCHAIN_BIN_PATH variable.

  3. To change SYSROOT or GNU PREFIX select Intel® System Studio Settings:



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

  5. Click OK to close the dialog.

Note

By default, the Intel® C++ compiler generates code for Intel® 64 architecture. If you want to generate code for IA-32 architecture, please specify compiler option -m32 in Project/Properties -> Intel C++ Compiler (or Intel C Compiler) -> Command Line -> Additional Options and Intel Linker -> Miscellaneous -> Additional options.

Note

Starting with Android NDK r16, you must specify the following:

-D__ANDROID_API__=<API version>

in Project/Properties -> C/C++ Build -> Intel C/C++ Compiler -> Command Line -> Additional Options.

For more details, see Unified Headers at https://android.googlesource.com/platform/ndk/+/ndk-release-r16/docs/UnifiedHeaders.md .

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

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 18.0 Developer Guide and Reference Supplement for Intel® System Studio 2018

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 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 adopt the Intel® C++ Compiler (icc) to the Yocto* Project v2.1 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/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 or later] target, use the following commands:

source /opt/intel/system_studio_yyyy/bin/compilervars.sh 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 2.1 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 for Linux* Host

Release Notes for Windows* Host

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

Intel® C++ Compiler 18.0 Developer Guide and Reference Supplement for Intel® System Studio 2018

Information specific to this product , and information about how to compile and optimize your application by using optimization tools and other libraries.

Intel® C++ Compiler 18.0 Developer Guide and Reference

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

Samples and Tutorials

Code samples and corresponding tutorials. Learn specific compiler optimizations, features, tools, and programming concepts.

NDK documentation

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

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.

Note that Intel® Cilk™ Plus is a deprecated feature.

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.