Getting Started with the Intel® C++ Compiler for Android*

Intel® C++ Compiler for Android* is compatible with the gcc compiler in the Android NDK and can be used to develop applications for x86-based devices that use Android OS. Software developers can use the Compiler from Windows*, OS X* or Linux* hosts. Intel C++ Compiler for Android is compatible with, and requires, the Android NDK, which can be found at http://developer.android.com/sdk/ndk/index.html.  

Intel C++ Compiler for Android is based on the Intel® C++ Compiler for Linux*, version 14.0. Not all features in the Linux compiler are available in the Intel C++ Compiler for Android. See the Release Notes for differences. Developers can take comfort in knowing that just about anything you can do in your gcc source code for your Android applications, you can also do with the Intel C++ Compiler for Android. You can even build applications that use gcc for devices based on ARM* Architecture and icc for devices based on Intel Architecture. It is highly compatible with gcc and tools in the NDK and SDK, while delivering outstanding app performance.

For this release of Intel C++ Compiler for Android, we offer documentation that is common across several Intel C++ product offerings, including, for example, Intel® C++ Composer XE, which is an offering for developers working on high-performance computing – applications that might be running on large, multi-processor servers or even compute-clusters.

This document presents getting-started information specific to the Intel® C++ Compiler for Android* and replaces the Getting Started section in the User and Reference Guide for Intel® C++ Compiler, version 14.0.

Throughout this Guide, we will refer to the Intel® C++ Compiler for Android as Intel® C++ Compiler, Compiler, or icc.

Building an Application for Android* with the Intel® C++ Compiler

You can develop 32-bit applications for x86-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.

After you install the Intel® C++ Compiler for Android*, the installation program integrates the Compiler into the Android NDK build system automatically. ICC will be the default compiler for x86 targets after installation. For details, see the Installation Guide.

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

Using the icc toolchain with the Android NDK Build System - Building a Sample Application

Now let us build for a target with NDK. We will use the "hello-jni" sample application that ships with the Android NDK. Here is an example how it may look in the File System:

Figure 1. The "hello-jni" app can be found in the "samples" directory under the Android NDK directory.
Stated differently, the path is: "$NDK_DIR/samples/hello-jni/jni".

 

You can build the sample application with the Intel® C++ Compiler using one of the options below:

  1. From the command line

    Open the terminal window and navigate to the "jni" folder of the sample

    cd $NDK/samples/hello-jni

    Use the following command:

    $ $NDK_DIR/ndk-build V=1 -B APP_ABI=x86

    where:

    V=1     enables verbose output (optional)

    -B     means rebuild all (optional)

    APP_ABI     indicates target architecture. If you want to target all architectures supported by the NDK, change this to "APP_ABI=all".

  2.  

  3. Or you may use the "Application.mk" file

    a. Open or create the “Application.mk” file in your application’s "jni" folder at "$NDK_DIR/samples/hello-jni/jni/"

    b. Add the following line in the Application.mk:

    APP_ABI:=x86

     

    c. Run the below command to build the application:

    $ $NDK_DIR/ndk-build V=1 –B

In either approach, you need to configure APP_ABI if you want to use ICC. If multiple versions of Intel compiler are installed, a full compiler package version can be specified. For example:

 

NDK_TOOLCHAIN=x86-icc14.x.y.nnn

where "x" is the minor version, "y" is the update number, "nnn" is the package build number.

Building an Application for Deployment

By default, the NDK is configured to build an application for debugging within Eclipse*, and all optimizations are turned off. When the code is ready for deployment, you need to compile it for performance.

  1. Open “Application.mk” file in your application’s "jni" folder at "$NDK_DIR/samples/hello-jni/jni/"
  2. To switch to the release mode, add the following line:

    APP_OPTIM:=release

     

  3. To target a specific processor, for example, to build application to run on the Intel® Atom™ processor, add the following line:

    APP_CFLAGS:=-xATOM_SSSE3

     

  4. To enable advanced optimizations of Intel® C++ Compiler, for example, to increase the optimization level, add the following line:

    APP_CFLAGS:=-xATOM_SSSE3 –O3

     

  5. To enable interprocedural optimizations, add:

    APP_CFLAGS:=-xATOM_SSSE3 –O3 –ipo

     

  6. Build the application

 

Note that the APP_OPTIM and APP_CFLAGS can be given as arguments in building from the command line. Here is an example:

$ ndk-build V=1 -B APP_ABI=x86 APP_OPTIM=release APP_CFLAGS=”-xATOM_SSSE3 –O3 -ipo”

For further details, refer to the “High-Level Optimizations (HLO)” and “Interprocedural Optimization (IPO)” sections in the Intel® C++ Compiler XE 14.0 User and Reference Guides supplied with the package or on the web.

Using the icc toolchain as a Standalone Compiler

  1. Open a terminal window.
  2. Set up the environment of the Intel Compiler with the following command:

    $ source [icc-install-dir]/bin/compilervars.sh

    where [icc-install-dir] is any directory you choose to install the compiler. By default, it is:

    /opt/intel/cc_android_14.x.y.nnn/

    where "x" is the minor version, "y" is the update number, "nnn" is the package build number.

     

    If you choose the default installation directory, use the following command: 

    $ source /opt/intel/cc_android_14.x.y.nnn/bin/compilervars.sh

 

If you saw errors requesting to set up ANDROID_SYSROOT and ANDROID_GNU_X86_TOOLCHAIN environment variables, the possible reason is that you are using an unsupported NDK version while installation. You can still set up the environment variables manually.

    If you installed the 32-bit version of the Android NDK, set the environment variables as follows:

    $ export NDK_DIR=[Android NDK-install-directory]

    export ANDROID_SYSROOT=$NDK_DIR/platforms/android-18/arch-x86
    $ export ANDROID_GNU_X86_TOOLCHAIN=$NDK_DIR/toolchains/x86-4.6/prebuilt/linux-x86

     

    If you installed the 64-bit version of Android NDK, set the environment variables as follows:

    $ export NDK_DIR=[Android NDK-install-directory]

    $ export ANDROID_SYSROOT=$NDK_DIR/platforms/android-18/arch-x86
    $ export ANDROID_GNU_X86_TOOLCHAIN=$NDK_DIR/toolchains/x86-4.6/prebuilt/linux-x86_64

 

You are now ready to use icc from a command line in the build environment where you can use “icc” to compile C source code and “icpc” to compile C++ source code. Here is an “icc” example:

$ cd $NDK_DIR/samples/hello-jni/jni
$ icc -c hello-jni.c
$ icc –shared -o libhello-jni.so hello-jni.o

Using Intel® C++ Compiler for Android* with Eclipse*

This section explains how to configure Eclipse and Eclipse projects to use icc for Android. Note, that you should have the Android Developer Toolkit (ADT) installed as a prerequisite. The ADT includes SDK components and a version of the Eclipse IDE with built-in Android Developer Tools.

Follow the instructions below to configure Eclipse and Eclipse projects to use Intel C++ Compiler.

  1. After installing ADT, start Eclipse. Figure 2 below shows a typical installation with an arrow pointing to the Eclipse executable used to start the IDE:

    Figure 2 shows a typical Eclipse installation with an arrow pointing to
    the Eclipse executable used to start the IDE.

     

  2. Configure Eclipse to use NDK plugin. From the Eclipse Window menu, select Preferences. This will open a new Preferences window:

    Figure 3. Eclipse showing the "Window" menu, from which you select "Preferences".

     

  3. In the Preferences window, select NDK under Android as shown in Figure 4 below, enter the NDK path in the NDK Location text box and click OK.

    Figure 4. "Preference" pop-up window focused on the Android NDK selection.
    This enables users to specify the NDK Location.

     

  4. Next, we will create a new project from the NDK samples. A series of screenshots below shows how to do this.

    a) From the Eclipse menu, select File > New > Project

       

         Figure 5. Creating a new project from NDK sample code. From the "File" menu, select "Project..."

     

    b) A pop-up window will appear called New Project. Select Android Project from Existing Code and click Next

       

       Figure 6. Creating a new project from NDK sample code. In the resulting pop-up, highlight "Android Project
       from Existing Code" and click "Next>".

     

    c) Import Project window opens. Browse to "[ndk-dir]/samples/hello-jni" directory, check the Copy projects into workspace check-box, and then click Finish.

       

       Figure 7. In the "Import Projects" pop-up window, confirm the project you want to load and make sure you
       put a check mark to "Copy projects into workspace". Then click "Finish."

     

       This will open the newly created project in the Project Explorer:

     

      Figure 8. The new created project opens in the Project Explorer.

     

  5. With our project loaded, let us add Native Support to Eclipse, which adds Java and C/C++ support. Configure the project to include Native Support as follows.

    a) Right-click on the project name in the Project Explorer window, select Android Tools > Add Native Support in the drop-down menu:

                 

                     Figure 9. Adding Native Support to a project loaded into Eclipse. Right-click
                     the project name, go to "Android Tools" and click "Add Native Support…"
                     

    b) A dialog will open asking for the Library Name. Set the library name to "hello-jni" as shown below. Click Finish:

               

                  Figure 10. Set the library name to "hello-jni". Click "Finish".

     

  6. Create a new “Application.mk” file under “jni” folder with the following line:

        APP_ABI:=x86

     

  7. To build your project, right-click on project name in the Project Explorer and select Build Project.

 

The application can now be tested on any x86-based Android device including an x86-based Android Virtual Device (AVD).

Using Advanced Features of the Intel® C++ Compiler for Android*

Read the article Using Advanced Intel(R) C++ Compiler Features for Android* Applications for details.

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

Read the online article Building Native Android* Apps Using Intel(R) C++ Compiler in Android Studio* for latest status. Please, note that the Android Studio support is a preview feature.

Next Steps

Read the Release Notes and Installation Guide for information on the product installation, new and changed features, and issues that are not described in the product documentation.

Read information in the User and Reference Guide for the Intel® C++ Compiler 14.0 supplied with this package.

Access the Intel(R) C++ Compiler for Android* Help from the Eclipse* IDE: start Eclipse*, go to Help>Help Content, find Intel(R) C++ Compiler for Android* Help in TOC.

Visit Intel® Developer Zone for more information about Intel® C++ Compiler for Android*.

Read the NDK documentation under $NDK/docs.

Contact your Intel representative for more information on Intel(R) C++ Compiler for Android*.

Optimization Notice

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804


Disclaimer and Legal Information

INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION WITH INTEL PRODUCTS. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. EXCEPT AS PROVIDED IN INTEL'S TERMS AND CONDITIONS OF SALE FOR SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL PRODUCTS INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.

A "Mission Critical Application" is any application in which failure of the Intel Product could result, directly or indirectly, in personal injury or death. SHOULD YOU PURCHASE OR USE INTEL'S PRODUCTS FOR ANY SUCH MISSION CRITICAL APPLICATION, YOU SHALL INDEMNIFY AND HOLD INTEL AND ITS SUBSIDIARIES, SUBCONTRACTORS AND AFFILIATES, AND THE DIRECTORS, OFFICERS, AND EMPLOYEES OF EACH, HARMLESS AGAINST ALL CLAIMS COSTS, DAMAGES, AND EXPENSES AND REASONABLE ATTORNEYS' FEES ARISING OUT OF, DIRECTLY OR INDIRECTLY, ANY CLAIM OF PRODUCT LIABILITY, PERSONAL INJURY, OR DEATH ARISING IN ANY WAY OUT OF SUCH MISSION CRITICAL APPLICATION, WHETHER OR NOT INTEL OR ITS SUBCONTRACTOR WAS NEGLIGENT IN THE DESIGN, MANUFACTURE, OR WARNING OF THE INTEL PRODUCT OR ANY OF ITS PARTS.

Intel may make changes to specifications and product descriptions at any time, without notice. Designers must not rely on the absence or characteristics of any features or instructions marked "reserved" or "undefined". Intel reserves these for future definition and shall have no responsibility whatsoever for conflicts or incompatibilities arising from future changes to them. The information here is subject to change without notice. Do not finalize a design with this information.

The products described in this document may contain design defects or errors known as errata which may cause the product to deviate from published specifications. Current characterized errata are available on request.

Contact your local Intel sales office or your distributor to obtain the latest specifications and before placing your product order.

Copies of documents which have an order number and are referenced in this document, or other Intel literature, may be obtained by calling 1-800-548-4725, or go to: http://www.intel.com/design/literature.htm.

Intel processor numbers are not a measure of performance. Processor numbers differentiate features within each processor family, not across different processor families. See http://www.intel.com/products/processor_number/ for details.

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice. Notice revision #20110804

Intel, Intel Atom, and Intel Core are trademarks of Intel Corporation in the U.S. and/or other countries.

*Other names and brands may be claimed as the property of others.

Copyright © 2014, Intel Corporation. All rights reserved.